2013-08-18 112 views
0

我使用Androids LinearLayout爲每個設備的不同分辨率。這樣我解決了垂直佈局問題不同的分辨率。android佈局垂直/水平權重

但我無法解決水平佈局問題。我的是我的佈局。我想要這樣構建佈局。

enter image description here

在這種情況下,我使用的左邊距/右但這不是在不同的分辨率下工作。如何放置TextView與分辨率有關?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/LinearLayout1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/background" 
android:orientation="vertical" > 

<TextView 
    android:id="@+id/titleView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="9" 
    android:gravity="center" 
    android:text="TextView" 
    android:textColor="#5a5856" 
    android:textSize="35sp" /> 

<TextView 
    android:id="@+id/wordDafinitionView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="3" 
    android:textSize="17sp" 
    android:layout_marginLeft="25dp" 
    android:layout_marginRight="30dp" 
    android:text="TextView" 
    android:textColor="#5a5856" /> 


<TextView 
    android:id="@+id/TextView01" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="9" 
    android:gravity="center" 
    android:text="TextView" 
    android:textColor="#5a5856" 
    android:textSize="35sp" /> 

</LinearLayout> 
+0

你的'截圖'說'拒絕轉介' –

回答

0

一種解決方法是你可以用

DisplayMetrics metrics = getResources().getDisplayMetrics(); 
int width = metrics.widthPixels; 
int height = metrics.heightPixels; 

閱讀屏幕尺寸和檢查不同設備的屏幕尺寸,

if((metrics.heightPixels/metrics.density) >= 700) 
       { 
        Log.e(" 10 inch Tab", " 10 inch Tab"); 
       } 
      else if((metrics.heightPixels/metrics.density) >= 550) 
       { 
        Log.e(" 7 inch Tab", " 7 inch Tab"); 
       } 
      else if((metrics.heightPixels/metrics.density) >= 400) 
       { 
        Log.e(" 5 inch Tab/Mobile", " 5 inch Tab/Mobile"); 
       } 
      else 
       { 
        Log.e("All other mobile devices", "All mobile other devices"); 
       } 

,然後設置你的TextView的寬度相應。

+0

這對我有用:) – user2637015