![](/img/trans.png)
[英]android:layout_alignParentTop=“true” and android:layout_centerVertical=“true” do not set the imageView centered at the the top of the screen
[英]RelativeLayout- android:layout_centerHorizontal=“true” and android:layout_centerVertical=“true” dont center the imageview
出於一些奇怪的原因android:layout_centerHorizontal="true"
和android:layout_centerVertical="true"
不要將ImageView
放在中心似乎不是我的ImageView
中心
有什么建議?
圖像卡在屏幕的右上角,並且沒有按預期居中。
資源:
*<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8sp"
android:layout_marginLeft="8sp"
android:layout_marginRight="8sp"
android:layout_marginTop="8sp"
android:background="@drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/emblem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:src="@drawable/apn_app_logo" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/start2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="8sp"
android:layout_toRightOf="@id/start" >
<Button
android:id="@+id/go_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="@drawable/apn_app_go_button" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/go_button"
android:layout_marginRight="8sp"
android:layout_marginTop="8sp"
android:gravity="center"
android:text="@string/start_text"
android:textColor="#000000"
android:textSize="18sp" />
</RelativeLayout>
</RelativeLayout>*
將centerHorizontal
移動到相對布局。 目前,您將圖像置於圖像視圖中心(基本上您將圖像置於視圖中心),您想要的是使內容居中的相對布局。
嘗試:
<RelativeLayout
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/emblem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:src="@drawable/apn_app_logo" />
</RelativeLayout>
另一種選擇是:
<RelativeLayout
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="@+id/emblem"
android:layout_width="match_parent" //change to match_parent
android:layout_height="match_parent" //change to match_parent
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:scaleType="fitStart"
android:src="@drawable/apn_app_logo" />
</RelativeLayout>
第二個選項設置的寬度和高度imageView
匹配relativeView
,這將允許您使用centerHorizontal
和centerVertical
在imageView
你不能在LinearLayout中使用android:layout_below。 您可以將這兩個項目放在RelativeLayout中,或者您可以將LinearLayout從“水平”更改為“垂直”,如下所示:
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.