开发者

Android: Why does my view fill the entire screen and not display the buttons at bottom

How do I stop my view from filling the entire screen and not showing my buttons at the bottom of the screen?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="fill_parent"
    android:layout_height="fill_parent"> 
<com.vig.comix.ImageZoomView
    android:id="@+id/zoomview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"    android:layout_alignParentTop="true" />
<LinearLayout android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"    android:layout_below="@+id/zoomview"    android:layout_alignParentBottom="true"> 
<ImageButton android:id="@+id/btnPrev"
    android:layout_width="wrap_content"     android:layout_height="wrap_content"    android:s开发者_开发百科rc="@android:drawable/ic_media_rew"
    android:background="@null"
    android:layout_weight="1"
    android:width="0px" /> 
<ImageButton android:id="@+id/btnNext"
    android:layout_width="wrap_content"     android:layout_height="wrap_content"    android:src="@android:drawable/ic_media_ff"
    android:background="@null"
    android:layout_weight="1"
    android:width="0px" /> 
<ImageButton android:id="@+id/btnMove"
    android:layout_width="wrap_content"     android:layout_height="wrap_content"    android:src="@android:drawable/btn_star"
    android:background="@null"
    android:layout_weight="1"
    android:width="0px" /> 
<ImageButton android:id="@+id/btnDelete"
    android:layout_width="wrap_content"     android:layout_height="wrap_content"    android:src="@android:drawable/ic_menu_delete"
    android:background="@null"
    android:layout_weight="1"
    android:width="0px" /> 
</LinearLayout> 
</RelativeLayout>

When I change my code and put the buttons at the top, it works fine. I have tried relative layouts, linear layouts, lauout weights, ...

What am I doing wrong?


RelativeLayout can be tricky to work with. I try to stick with FrameLayout and LinearLayout. Here is a sketch of the layout I would use in your case:

<LinearLayout orientation="vertical">
    <ImageZoomView layout_weight="1" layout_height="wrap_content">
    <LinearLayout orientation="horizontal" layout_height="wrap_content">
        ... buttons ...
    </LinearLayout>
</LinearLayout>

Heights and widths are fill_parent when not mentioned. The layout_weight attribute on the ImageZoomView will cause it to expand as far as it can without squishing your bottom buttons.


Instead of putting android:layout_below in your LinearLayout. Try removing that and put

android:layout_above="@+id/myLinearLayout"

inside your ImageZoomView. Of course giving your LinearLayout the same id.


Perhaps the layout_weight is causing issues? Also it doesn't seem like you're give the items an object to be positioned relative to?


Change this:

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

to this:

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜