Android图片 - 设置为保持在视图的底部

时间:2017-01-01 06:09:40

标签: android

我有一个位于相对视图中的图像,我想设置它以使其与视图的底部对齐,此时它只是居中(参见下面的屏幕抓取)。我可以通过设置一个上边距来实现这种对齐,但这对我来说似乎不对,因为这可能会因使用的设备而异。有没有办法简单地实现这一目标? (当前屏幕抓取和下面的代码)

enter image description here

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="0.7"
            android:background="@color/main_bg_color">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src = "@drawable/feature_compliment"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="0dp" />

            <Button
                android:id="@+id/exit_btn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@android:color/transparent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:text="@string/home"
                android:textStyle="bold"
                android:textSize="15sp"
                android:textColor="@android:color/black"
                android:alpha="0.5" />

            <Button
                android:id="@+id/sign_btn"
                android:layout_width="90dp"
                android:layout_height="50dp"
                android:layout_alignParentRight="true"
                android:layout_alignParentTop="true"
                android:text="@string/sign"
                android:background="@color/primary_button_color"
                android:textColor="@color/white"
                android:textSize="15sp"/>
        </RelativeLayout>

2 个答案:

答案 0 :(得分:2)

更改

android:layout_width="match_parent"
android:layout_height="match_parent"

android:layout_width="wrap_content"
android:layout_height="wrap_content"

答案 1 :(得分:0)

将android:layout_height设置为&#34; wrap_content&#34;

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dip"
    android:layout_weight="0.3"
    android:background="@color/colorPrimary">
   <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="0dip"
      android:layout_weight="0.7"
      android:background="@color/colorPrimary">

      <ImageView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:src = "@drawable/sample_background"
          android:layout_alignParentBottom="true"
           />

       <Button
        android:id="@+id/exit_btn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="@string/home"
        android:textStyle="bold"
        android:textSize="15sp"
        android:textColor="@android:color/black"
        android:alpha="0.5" />

       <Button
        android:id="@+id/sign_btn"
        android:layout_width="90dp"
        android:layout_height="50dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="@string/signUp"
        android:background="@color/colorPrimaryLight"
        android:textColor="@color/text_color_white"
        android:textSize="15sp"/>
   </RelativeLayout>