سؤال

I have two Linear layouts in a xml file, one contains a textview follwed by list view. The next layout should be shown below the list view, which shows the description of selected item in listview as textview. Is this possible ? Below code doesn't show TextView01. In what other way i can do it, if it's not possible by this simple way?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF88334C"
android:orientation="vertical"
>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="20dp"
    android:layout_marginTop="20dp"
    android:text="@string/hello_world"
    android:textColor="#FFAABBFF" />

<ListView
    android:id="@android:id/list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="48dp" >
</ListView>
<LinearLayout 

android:id="@+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF88334C"
android:orientation="vertical"
>

<TextView
    android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/byebye_world"
    android:textColor="#FFAEEEFF" />
</LinearLayout>

</LinearLayout>
هل كانت مفيدة؟

المحلول

try below code:-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FF88334C"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:text="hello_world"
        android:textColor="#FFAABBFF" />

    <ListView
        android:id="@android:id/list"
        android:layout_below="@+id/textView1"
        anndroi:layout_above="@+id/LinearLayou"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
              >
    </ListView>

    <LinearLayout
        android:id="@+id/LinearLayou"
               android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FF88334C"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:orientation="vertical" >

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="byebye_world"
        android:textColor="#FFAEEEFF" />
    </LinearLayout>

</RelativeLayout>

نصائح أخرى

you need to use layout_weight attribute for this. try this layout

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF88334C"
android:orientation="vertical"
>

<LinearLayout 

android:id="@+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF88334C"
android:orientation="vertical"
android:layout_weight="1"
>

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="20dp"
    android:layout_marginTop="20dp"
    android:text="@string/hello_world"
    android:textColor="#FFAABBFF" />

<ListView
    android:id="@android:id/list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="48dp" >
</ListView>
</LinearLayout>

<LinearLayout 

android:id="@+id/LinearLayou"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF88334C"
android:orientation="vertical"
android:layout_weight="2"
>

<TextView
    android:id="@+id/TextView01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/byebye_world"
    android:textColor="#FFAEEEFF" />
</LinearLayout>

</LinearLayout>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top