我正在嘗試解決佈局問題 - 我在Moto G上測試了這個res/layout/my.xml,這很好,但是當我在Nexus S上測試它時按鈕太大了。我嘗試res/layout-xhdpi/my.xml(因爲Moto G是xhdpi,而Nexus只是hdpi),但總是其中一個佈局在兩個上都膨脹,從來沒有不同(對於我現在使用的xhdpi,現在使用帶文本的按鈕,所以我可以即時看到,如果它繼續):Nexus S和Moto G - 不能區分佈局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:cropToPadding="true"
android:src="@drawable/pil2" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:height="90dp"
android:minWidth="150dp" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2"
android:height="80dp"
android:minWidth="150dp" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_alignParentTop="true"
android:height="130dp"
android:minWidth="150dp" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button4"
android:layout_centerHorizontal="true"
android:height="90dp"
android:minWidth="150dp" />
</RelativeLayout>
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="xxxx"
ads:adSize="BANNER" />
</LinearLayout>
在可繪製資源以外的任何地方使用密度資源集限定符(例如'-hdpi')是一種嚴重的代碼異味,因爲它幾乎可以確保你不會得到你想要的東西。除此之外,使用層次結構視圖來確定您的佈局規則中的哪些內容會導致您的困難。 – CommonsWare 2014-10-05 12:06:42
這就是它在Nexus S上的樣子:http://oi58.tinypic.com/oko8l1.jpg這就是它在Nexus 5上的樣子:http://oi59.tinypic.com/1zlgjud.jpg當然按鈕是在使它們正常工作之後,瑪德是透明的。從頂部的第一個按鈕沒有功能 - 只是佔位符,而不是margingTop。我一直在重新考慮自己的用戶界面,但無法讓這個東西變得牢固,所以任何設備都能正常工作。 – 2014-10-05 12:19:13
這似乎是你試圖使該PNG/JPEG /任何背景可點擊的「按鈕」。你的方法不可靠,因爲按鈕與整體背景無關。 – CommonsWare 2014-10-05 12:26:32