2013-08-18 201 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