如何将屏幕均匀划分为3?

时间:2011-08-17 22:33:04

标签: android android-layout

我已经在使用这个计算了:

size = act.getWindow().getDecorView().getWidth()/3;

int dip = (int)TypedValue.applyDimension(
                 TypedValue.COMPLEX_UNIT_DIP,
                 size,
                 r.getDisplayMetrics()
          );

然而,我的图像太大了。我需要做什么?

1 个答案:

答案 0 :(得分:5)

在定义XML时,一种简单的方法是布局权重:

 <LinearLayout
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical">

     <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/example" 
        weight="1" />

     <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/example" 
        weight="1" />

     <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/example" 
        weight="1" />

  </LinearLayout>

您还可以使用ScaleType属性来更改图像的缩放方式,希望这会有所帮助!

相关问题