当前位置: 动力学知识库 > 问答 > 编程问答 >

Table/List Layout in Android

问题描述:

I'm currently developing an Android application, and I need to do sth. like this:

(I know It's in german, but you get the idea)

How could I achieve this?

网友答案:

Personally I would do this using two nested LinearLayouts. One vertical LL for each row, and in each a horizontal LL for individual rows:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/text_view_one"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Speicherort"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Meine Dateien"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Ordnerpfad"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="/storage/emulated/0"/>

    </LinearLayout>

</LinearLayout>

By setting the width of the TVs to 0dp and both layout weights to 1 this means they will each take up 50% of the width, so the right and left sides will be divided evenly.

If you need to change the text programatically, just search for the id and use setText():

TextView textView = (TextView) findViewById(R.id.text_view_one);
textView.setText("Speicherort");
网友答案:

So what you want is a row that is divided equally right?

You can do this by wrapping the row in a LinearLayout and setting android:layout_width="0dp" and android:layout_weight="1" to each of the TextView's.

Or you could use a PercentRelativeLayout.

分享给朋友:
您可能感兴趣的文章:
随机阅读: