I am newbie to Android development (in fact I have downloaded ADK today) and I want to create simple setting page with two columns. In first column should be the text and in second column should be button/slider/etc.

My problem is that when I use LinearLayout, only FULL WIDTH TEXT is visible. Columns are shown "outside" of screen on the right side of text.

This is how the screen should look like.

/-----------------\
| FULL WIDTH TEXT |
|                 |
| Column1 Column2 |
| Column1 Column2 |
\-----------------/

There is content of my XML file:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:weightSum="2"
android:orientation="horizontal"
>

<TextView
    android:id="@+id/textview_settings_hint"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/settings_hint" />

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="vertical"
    android:visibility="visible" >

    <CheckBox
        android:id="@+id/checkbox_motion_sensor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/checkbox_motion_sensor" />

    <CheckBox
        android:id="@+id/checkbox_light_sensor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/checkbox_light_sensor" />

    <CheckBox
        android:id="@+id/checkbox_shake_sensor"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/checkbox_shake_sensor" />
</LinearLayout>

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="vertical"
    android:visibility="visible" >

    <SeekBar
        android:id="@+id/seekbar_motion_sensor_sensitivity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>     

How can I set the inner layouts to be drawn on bottom of TextView? Thank you for your help.

有帮助吗?

解决方案

Your items are being set to the right of the screen, because your root linear layout has the property of orientation horizontally, so, the first element is being shown, and the next element is being pushed to the right of the screen. In order to fix that specific issue, just change property to vertically and you will notice that your inner layouts are stocking all the elements one on top of another, in order to get the "two" colums effect, you need to create another horizontal layout after the first text view, that way you are telling the inflater that, the first text will be set on top of your horizontal columns. Just as advice, what you are trying to do could be simply done either with TableLayout or RelativeLayout, you should take a look on them...

Regards!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top