简体   繁体   English

显示RelativeLayout的ImageView顶部

[英]Show ImageView top of RelativeLayout

I have placed an ImageView at the top of a RelativeLayout but the image does not show at the top of the page. 我在RelativeLayout的顶部放置了一个ImageView,但图像没有显示在页面顶部。 I searched the internet and I added android:scaleType="fitStart" and the problem was solved, but image gets more space in page because when I add a second image below this image, the second image shows at the center of the page! 我搜索了互联网,我添加了android:scaleType="fitStart" ,问题解决了,但是图像在页面中获得了更多的空间,因为当我在这个图像下面添加第二个图像时,第二个图像显示在页面的中心! What is the problem? 问题是什么? How can i solve this? 我怎么解决这个问题? I tried using a LinearLayout which produces same result. 我尝试使用LinearLayout产生相同的结果。

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

<ImageView
    android:id="@+id/registerAction"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:scaleType="fitStart"
    android:src="@drawable/register_action" />

<ImageView
    android:id="@+id/registerLogo"
    android:src="@drawable/app_pass"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_below="@id/registerAction"/>
<EditText
    android:id="@+id/pass1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/registerLogo"
    android:paddingTop="15dp"
    android:layout_marginRight="10dp"
    android:layout_marginLeft="10dp"
    android:inputType="textPassword"
    android:hint="@string/pass1"
    android:gravity="right"/>
<EditText
    android:id="@+id/pass2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/pass1"
    android:paddingTop="15dp"
    android:layout_marginRight="10dp"
    android:layout_marginLeft="10dp"
    android:inputType="textPassword"
    android:hint="@string/pass2"
    android:gravity="right"/>
<Button
    android:id="@+id/btn"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/pass2"
    android:paddingRight="10dp"
    android:paddingLeft="10dp"
    android:paddingTop="30dp"/>
</RelativeLayout>

Thanks.Cheers Thanks.Cheers

EDIT: and another question How can i padding Button 30dp in below of EditText? 编辑:和另一个问题如何在EditText下面填充Button 30dp? when i changed PaddingTop of Button not changed position of Button. 当我更改Button的PaddingTop时没有改变Button的位置。

// try this
<?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">

    <ImageView
        android:id="@+id/registerAction"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:adjustViewBounds="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/register_action" />

    <ImageView
        android:id="@+id/registerLogo"
        android:src="@drawable/app_pass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/registerAction"/>
    <EditText
        android:id="@+id/pass1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/registerLogo"
        android:paddingTop="15dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:inputType="textPassword"
        android:hint="@string/pass1"
        android:gravity="right"/>
    <EditText
        android:id="@+id/pass2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/pass1"
        android:paddingTop="15dp"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:inputType="textPassword"
        android:hint="@string/pass2"
        android:gravity="right"/>
    <Button
        android:id="@+id/btn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/pass2"
        android:paddingRight="10dp"
        android:paddingLeft="10dp"
        android:paddingTop="30dp"/>
</RelativeLayout>

Try this: 试试这个:

Make your relative layout height wrap_content. 使您的相对布局高度为wrap_content。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM