我是初學者。我正在開發一個應用程序,面臨佈局的一個奇怪問題。 當我在小設備上運行我的應用程序時,它工作正常,但是當我在大屏幕設備上運行它時,其佈局屬性會自動更改。 請讓我知道是否有任何方法可以以編程方式爲所有屏幕尺寸創建單個佈局? 我的XML是,Android - 如何爲多個屏幕設置單一佈局
<RelativeLayout android:id="@+id/contents"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="@+id/imgBtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/panchangtab1" />
<ImageButton
android:id="@+id/imgBtn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_toRightOf="@+id/imgBtn1"
android:background="@drawable/horoscopetab1" />
</RelativeLayout>
在這裏我得到的第一圖像確定,但第二圖像是不實際尺寸。
找到屏幕大小並通過在java中設置頁邊距來修復它的代碼 –
@Ashish Patil你不應該給應用程序中使用的組件設置任何固定值。將組件的寬度和高度設置爲「match_parent」,「 WRAP_CONTENT」, 「FILL_PARENT」。 – Ram