How to create a neat two-columns input form in Android?

后端 未结 2 465
误落风尘
误落风尘 2021-02-07 09:15

I want to create a neat two-columns input form like this:

\"http://img31.imageshack.us/img31/115/addnew2.png\"

相关标签:
2条回答
  • 2021-02-07 10:00

    Alright, I found out the way with LinearLayout. The trick is by wrapping the Views that you want to resize with LinearLayout. Then the width of View itself can be adjusted by using: android:layout_width or android:ems property.

    Here is the xml code:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
    
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:text="@string/lblTitle" />
    
            <EditText
                android:id="@+id/txtTitle"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.75"
                android:ems="10" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
    
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:text="@string/lblAuthor" />
    
            <EditText
                android:id="@+id/txtAuthor"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.75"
                android:ems="10" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
    
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:text="@string/lblPublisher" />
    
            <EditText
                android:id="@+id/txtPublisher"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.75"
                android:ems="10" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
    
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_weight="0.25"
                android:text="@string/lblIsbn" />
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.75"
                android:orientation="horizontal" >
    
                <EditText
                    android:id="@+id/txtIsbn"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ems="5" />
            </LinearLayout>
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
    
            <View
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.25" />
    
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.75"
                android:orientation="horizontal" >
    
                <Button
                    android:id="@+id/btnSubmit"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ems="5"
                    android:text="@string/submit" />
    
                <Button
                    android:id="@+id/btnCancel"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ems="5"
                    android:text="@string/cancel" />
            </LinearLayout>
        </LinearLayout>
    
    </LinearLayout>
    
    0 讨论(0)
  • 2021-02-07 10:06

    you should also consider the gridLayout , which can be used (by using an android library) on API7+ .

    here's a link: http://android-developers.blogspot.com/2011/11/new-layout-widgets-space-and-gridlayout.html

    0 讨论(0)
提交回复
热议问题