![](/img/trans.png)
[英]Why are my eclipse dp dimensions for the android graphical layout editor not accurate?
[英]Eclipse Android Layout: Without dp-values?
如果要在布局的中心放置圖片,則可以輕松使用:“垂直居中”和“水平居中”。 但是現在我想要一張圖片放在左側的中心。 但是我不想使用marginLeft = .. dp。 我想在沒有dp的情況下工作。 有沒有像“垂直居中”之類的可能性? 這是帶有dp值的代碼。 我可以使用什么代替MarginLeft“ 38dp”?
<?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="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_centerInParent="true"
android:layout_marginLeft="41dp"
android:src="@drawable/rosezwei" />
</RelativeLayout>
采用
android:layout_gravity="left|center_vertical"
將在LinearLayout視圖內工作。
<?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" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="left|center_vertical"
android:src="@drawable/rosezwei" />
</LinearLayout >
請注意,LinearLayout是水平的,因此視圖可以選擇其VERTICAL位置。
如果我正確理解,您希望圖像中心位於屏幕寬度的25%...
las Android沒有XML百分比,因此必須使用LinearLayout
拆分屏幕
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:layout_gravity="center"
android:src="@drawable/rosezwei" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".5"/>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.