代码之家  ›  专栏  ›  技术社区  ›  LoneWolfPR

android:2.2版(froyo)中的布局边缘底部似乎无法正常工作

  •  11
  • LoneWolfPR  · 技术社区  · 14 年前

    我在相对布局中有这个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"
        />
    

    这将在Android 1.6上正常和高密度分辨率屏幕上的预期位置绘制图像,但是在2.2上,它似乎忽略了布局“边缘底部”,始终在底部绘制对齐的图像。以前有人见过这个吗?如果有,你知道解决方法吗?

    编辑1:

    它位于一个相对的布局内,这是周四宣布的:

    <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">
    

    编辑2:

    以下是完整的布局代码:

    <?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>
    

    编辑3

    alt text

    5 回复  |  直到 11 年前
        1
  •  14
  •   lcoq    13 年前

    FrameLayout 添加一个 View 包括以下内容:

    android:id="@+id/gap"
    android:layout_width="wrap_content"
    android:layout_height="0dip"
    android:layout_alignParentBottom="true"
    

    现在,为了解决 layout_marginBottom ,使用上面的内容:

    android:layout_above="@+id/gap"
    
        2
  •  3
  •   LoneWolfPR    14 年前

    好吧,经过大量的搜索,我找到了一个链接,这个问题实际上可以追溯到09年,但是2010年的评论显示了在2.2中AlignParentBottom有很多问题。 http://code.google.com/p/android/issues/detail?id=1394

    所以,我做了一个解决方法,把整个东西放在一个框架布局中,让ImageView成为我相对布局之外的一个子视图,并与布局重力一起放置。这就成功了,并使它在所有版本中都起作用。最后的代码是:

    <?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>
    
        3
  •  1
  •   Octavian Helm    14 年前

    Android 1.6对我来说是一样的,直到我改变了 layout_height fill_parent 最外层的相对布局`

    显然,当设置为 wrap_content . 如果没有特殊的理由 RelativeLayout 的宽度和高度,以包装它的内容,我会说,指定它像那样。

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/excusescreen"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/woodbg"
        android:clipChildren="true">
        <!-- all the other stuff -->
    </RelativeLayout>
    
        4
  •  1
  •   Maria Neumayer    12 年前

    如果不想添加其他视图,可以使用 InsetDrawable 具有 android:insetBottom 集合。

        5
  •  1
  •   Joris Kroos    11 年前

    我们也遇到了同样的问题,用parentBottom定位的线性布局,给它一个填充,并把图像/按钮/视图放在里面。在目标上使用边距,而不是在线性布局上使用填充,这同样适用于btw。