ListView with a diffrent number of TextView in And

2020-01-20 09:43发布

问题:

I want to create a layout that will have n numbers of textview on the left side and have listView on the right side .And the top of right side have above listview i need to have to buttons .Something like this :

   |Button1||Button2|
-------------------
|TEXTView|ListView  |
|TEXTView|          |
|TEXTView|          |
|TEXTView|          |
|TEXTView|          |

I tried something like this but it is not working for me

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:orientation="horizontal" >
        <Button
            android:id="@+id/btnClear"
            android:layout_width="90dp"
            android:layout_height="50dp"
            android:layout_gravity="right|center"
            android:gravity="right|center"
            android:text="Clear" />
        <Button
            android:id="@+id/btnApply"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right|center"
            android:gravity="right|center"
            android:text="Clear" />
        </LinearLayout>
        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >
                <TextView
                    android:id="@+id/txtBrand"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:text="Brand" />
        </LinearLayout>
         <LinearLayout
             android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <ListView
            android:id="@+id/subCategory"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="6"
            android:cacheColorHint="@android:color/transparent"
            android:divider="@android:color/transparent"
            android:fadingEdge="none" />
    </LinearLayout>

</LinearLayout>

Kindly suggest me the changes in this

回答1:

Change your child linear layout orientation to horizontal

   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <TextView
            android:id="@+id/txtBrand"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="Brand" />
        <ListView
            android:id="@+id/subCategory"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="6"
            android:cacheColorHint="@android:color/transparent"
            android:divider="@android:color/transparent"
            android:fadingEdge="none" />
    </LinearLayout>


回答2:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@android:color/white">
<LinearLayout
        android:id="@+id/first"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <Button android:layout_weight="0.5"
            android:layout_width="0dp"
            android:layout_height="wrap_content"/>
    <Button android:layout_weight="0.5"
            android:layout_width="0dp"
            android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
        android:id="@+id/second"
        android:orientation="vertical"
        android:layout_below="@+id/first"
        android:layout_width="100dp"
        android:layout_height="match_parent">
    <TextView android:text="AAA" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
    <TextView android:text="AAA" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
    <TextView android:text="AAA" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
    <TextView android:text="AAA" android:layout_width="wrap_content" android:layout_height="wrap_content"/>

</LinearLayout>
<ListView
        android:layout_below="@+id/first"
        android:layout_toRightOf="@id/second"
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

</ListView>
</RelativeLayout>