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

hun*_*erp 0 android android-layout

我已经在使用这个计算:

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

int dip = (int)TypedValue.applyDimension(
                 TypedValue.COMPLEX_UNIT_DIP,
                 size,
                 r.getDisplayMetrics()
          );
Run Code Online (Sandbox Code Playgroud)

但是,我的图像太大了.我需要做什么?

Ljd*_*son 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>
Run Code Online (Sandbox Code Playgroud)

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