我在Relative布局中有这个ImageView块:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="50dip"
android:layout_marginLeft="81dip"
android:src="@drawable/swipehelp"
/>
Run Code Online (Sandbox Code Playgroud)
这将图像绘制在Android 1.6上的普通和高密度分辨率屏幕中的预期位置,但是在2.2上它似乎忽略了layout_marginBottom并始终在底部绘制对齐的图像.有没有人见过这个,如果有,你知道修复吗?
它位于如此声明的RelativeLayout内:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/excusescreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/woodbg">
Run Code Online (Sandbox Code Playgroud)
这是完整的布局代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/excusescreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/woodbg">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imlateTopBar"
android:layout_width="fill_parent"
android:layout_height="44dip"
android:background="@drawable/topandbottombars"
android:layout_alignParentTop="true"
>
<ImageView
android:id="@+id/excHomeBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="7dip"
android:src="@drawable/catexcusehomebtn"
>
</ImageView>
<ImageView
android:id="@+id/excBackToCatsBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="7dip"
android:src="@drawable/backtocats"
>
</ImageView>
</LinearLayout>
<ViewFlipper
android:id="@+id/excuses"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dip"
>
</ViewFlipper>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imlateTopBar"
android:layout_width="fill_parent"
android:layout_height="44dip"
android:background="@drawable/topandbottombars"
android:layout_alignParentBottom="true"
>
<ImageView
android:id="@+id/emailItBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="7dip"
android:src="@drawable/emailit"
>
</ImageView>
<TextView
android:id="@+id/numExcusesText"
android:layout_width="100dip"
android:layout_height="30dip"
android:layout_marginLeft="5dip"
android:layout_marginTop="7dip"
android:textColor="#66ffffff"
android:gravity="center"
android:textSize="18dip"
android:textStyle="bold"
android:text="1/13"
>
</TextView>
<ImageView
android:id="@+id/shareItBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="7dip"
android:src="@drawable/shareit"
>
</ImageView>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="50dip"
android:layout_marginLeft="81dip"
android:src="@drawable/swipehelp"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

小智 14
在FrameLayout添加a中View使用以下内容:
android:id="@+id/gap"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_alignParentBottom="true"
Run Code Online (Sandbox Code Playgroud)
现在,为了修复layout_marginBottom,使用上面的:
android:layout_above="@+id/gap"
Run Code Online (Sandbox Code Playgroud)
好吧,经过大量搜索后,我找到了这个问题的链接,该问题实际上可以追溯到 09 年,但 2010 年的评论显示 2.2 中的alignParentBottom 存在很多问题。 http://code.google.com/p/android/issues/detail?id=1394
因此,我做了一个解决方法,将整个内容放入 FrameLayout 中,并使 ImageView 成为相对布局外部的子级,并与layout_gravity 一起放置。这成功了,并使其在所有版本中都能工作。这是最终的代码:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/excusescreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/woodbg"
android:clipChildren="true">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imlateTopBar"
android:layout_width="fill_parent"
android:layout_height="44dip"
android:background="@drawable/topandbottombars"
android:layout_alignParentTop="true"
>
<ImageView
android:id="@+id/excHomeBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="7dip"
android:src="@drawable/catexcusehomebtn"
>
</ImageView>
<ImageView
android:id="@+id/excBackToCatsBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:layout_marginTop="7dip"
android:src="@drawable/backtocats"
>
</ImageView>
</LinearLayout>
<ViewFlipper
android:id="@+id/excuses"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dip"
>
</ViewFlipper>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imlateTopBar"
android:layout_width="fill_parent"
android:layout_height="44dip"
android:background="@drawable/topandbottombars"
android:layout_alignParentBottom="true"
>
<ImageView
android:id="@+id/emailItBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="7dip"
android:src="@drawable/emailit"
>
</ImageView>
<TextView
android:id="@+id/numExcusesText"
android:layout_width="100dip"
android:layout_height="30dip"
android:layout_marginLeft="5dip"
android:layout_marginTop="7dip"
android:textColor="#66ffffff"
android:gravity="center"
android:textSize="18dip"
android:textStyle="bold"
android:text="1/13"
>
</TextView>
<ImageView
android:id="@+id/shareItBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="7dip"
android:src="@drawable/shareit"
>
</ImageView>
</LinearLayout>
</RelativeLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="50dip"
android:src="@drawable/swipehelp"
/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23300 次 |
| 最近记录: |