簡體   English   中英

顯示RelativeLayout的ImageView頂部

[英]Show ImageView top of RelativeLayout

我在RelativeLayout的頂部放置了一個ImageView,但圖像沒有顯示在頁面頂部。 我搜索了互聯網,我添加了android:scaleType="fitStart" ,問題解決了,但是圖像在頁面中獲得了更多的空間,因為當我在這個圖像下面添加第二個圖像時,第二個圖像顯示在頁面的中心! 問題是什么? 我怎么解決這個問題? 我嘗試使用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

編輯:和另一個問題如何在EditText下面填充Button 30dp? 當我更改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>

試試這個:

使您的相對布局高度為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