开发者

How to get UI to look right

I am having a problem getting the ListView to display properly. It currently looks like this with the following xml code:

How to get UI to look right

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:background="@drawable/favs_main">
    <Button
        android:text="Return to Home"
        android:id="@+id/return_button"
        android:layout_width=开发者_如何学编程"150dp" 
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:textSize="15sp"/>
    <ListView
        android:id="@+id/favsListView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="180dp"
        android:layout_above="@id/return_button"/>
</RelativeLayout>

If you notice the list is down on the screen. I want it to be just below the favorites text instead of just above the return to home button. The catch however is that I always want the button to show and the list view to just occupy the space between the favorites text and the button. The text is from the background image so I can't just align below that. So even with 100 items I would still like to show the button.

Thanks for the help


If the word "favorites" is part of a background image as suggested in the RelativeLayout's background attribute, then you won't be able to align an element below it without using hacky margins or something to that effect. If you want to align an element below the word, separate that into a different ImageView and set the layout_below of the ListView to the id of that ImageView. To get an element to align properly in between two other elements, use a combination of layout_above and layout_below.


Couldn't you just align the ListView to the Parents' Top and set a margin for the ListView so that it is below the Text of the Background? Also you could change the background to provide the Text in an ImageView and align the ListView to be below the ImageView.


Instead of trying to make a persistent View always show up under the ListView and align it (which you can do, see other suggestions), you might want to take a look at using a footerView:

http://developer.android.com/intl/de/reference/android/widget/ListView.html#addFooterView

"Add a fixed view to appear at the bottom of the list."

Note that it can be another layout too if you eventually need to do more than just one Button.


this my listview which have multiple entries and textview and button fixed in the botton. i haven't inserted background. try this hope it will help.

http://www.techuv.com/layout-with-butoon-and-textview-fixed-in-bottom/


You could use a simple LinearLayout and use the weight attribute on the ListView :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="wrap_content"
  android:layout_height="fill_parent"
  android:background="@drawable/favs_main">
     <TextView 
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
     />
     <ListView
         android:id="@+id/favsListView"
         android:layout_width="wrap_content"
         android:layout_weight="1"
         android:layout_height="wrap_content"
         android:layout_marginTop="180dp"/>
     <Button
         android:text="Return to Home"
         android:id="@+id/return_button"
         android:layout_width="150dp" 
         android:layout_height="wrap_content"
         android:layout_marginTop="10dp"
         android:layout_centerHorizontal="true"
         android:textSize="15sp"/>
 </LinearLayout>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜