如何将ImageView设置到底部?

时间:2014-11-11 08:02:23

标签: android xml

我有下一个模板:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/fight"
    tools:context="ru.net.babobka.FightActivity" >

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="150dp"
        android:layout_height="180dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:src="@drawable/ken1" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="150dp"
        android:layout_height="190dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:src="@drawable/ryu1" />

</RelativeLayout>

结果是:

enter image description here

正如您所看到的,图像和底部边框之间有一个空格。如何避免?

3 个答案:

答案 0 :(得分:1)

您的相对布局有填充。这意味着它将向内推送所有内容。删除填充。

答案 1 :(得分:1)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:gravity="bottom|left"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ken1" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical" 
    android:gravity="bottom|right">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ryu1" />
</LinearLayout>

答案 2 :(得分:1)

像这样修改你的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/fight"
android:layout_alignParentBottom="true"
tools:context="ru.net.babobka.FightActivity" >

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="150dp"
    android:layout_height="180dp"
    android:layout_alignParentLeft="true"
    android:src="@drawable/ken1" />

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="150dp"
    android:layout_height="190dp"
    android:layout_alignParentRight="true"
    android:src="@drawable/ryu1" />

</RelativeLayout>