布局 XML 檔案
activity_one - 360dp 以上
activity_two - 480dp 以上
activity_three -600dp 以上
java檔案不同大小不同布局
super.onCreate(savedInstanceState);
//getSupportActionBar().hide();
setContentView(R.layout.activity_one);
uj5u.com熱心網友回復:
這會幫助你:
https://developer.android.com/guide/topics/large-screens/support-different-screen-sizes
真正干凈的方法是為其創建檔案夾:
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
這很酷 :
res/layout/main_activity.xml # For handsets
res/layout-land/main_activity.xml # For handsets in landscape
res/layout-sw600dp/main_activity.xml # For 7” tablets
res/layout-sw600dp-land/main_activity.xml # For 7” tablets in landscape
您可以為橫向位置創建獨占布局。
uj5u.com熱心網友回復:
也許試試它的 java 代碼更清晰:-
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Configuration config = getResources().getConfiguration();
if (config.smallestScreenWidthDp >= 320) {
setContentView(R.layout.activity_one);
} else if (config.smallestScreenWidthDp >= 480) {
setContentView(R.layout.activity_two);
} else if (config.smallestScreenWidthDp >= 600) {
setContentView(R.layout.activity_three);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/368399.html
