简体   繁体   中英

Android: Place textView below ListView

In my app, I would like to have a TextView DIRECTLY below a ListView. So if the ListView ends somewhere half of the screen, the TextView must be right there in the middle of the screen. But if the ListView covers more then the screen, so you have to scroll trough it, you also have to scroll for the TextView as its below the ListView. Have you got any idea on how to do that?

Thanks in advance!

you may add a footer to your ListView . you can use the example provided in this link

View footerView = ((LayoutInflater) ActivityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);
ListView.addFooterView(footerView);

You can add a header and footer view to a ListView. Both views then scroll with the other list items. Check addFooterView() .

you can use following layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ListView
    android1:id="@+id/listView1"
    android1:layout_width="match_parent"
    android1:layout_height="wrap_content"
    android1:layout_alignParentLeft="true"
    android1:layout_alignParentTop="true" >

</ListView>

   <TextView
       android1:id="@+id/textView1"
       android1:layout_width="wrap_content"
       android1:layout_height="wrap_content"
       android1:layout_alignParentBottom="true"
       android1:layout_below="@+id/listView1"
       android1:layout_centerHorizontal="true"
       android1:text="TextView" />

</RelativeLayout>

Use layout_weight to set the weight of the view.

 <ListView android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="8" android:id="@+id/ght" /> <EditText android:id="@+id/eld" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="2"> </EditText>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM