根据屏幕为视图定义相同的高度?

时间:2016-08-12 07:51:37

标签: android android-xml

如何显示所有高度相等的图像,它应该与任何设备上的父图像相匹配? 我该如何设计呢?

图像就是例子。

enter image description here

desing.xml

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

<ImageView
    android:layout_width="match_parent"
    android:layout_height="170dp"
    android:id="@+id/img1"
    android:src="@drawable/img1" />
<ImageView
    android:layout_width="match_parent"
    android:layout_height="170dp"
    android:id="@+id/img2"
    android:src="@drawable/img2" />
<ImageView
    android:layout_width="match_parent"
    android:layout_height="170dp"
    android:id="@+id/img3"
    android:src="@drawable/img3" />

 </LinearLayout>

这里我设置的高度为170dp,这仅适用于此屏幕,但在较大的屏幕中,图像不适合。
我想让它适合任何屏幕。

2 个答案:

答案 0 :(得分:1)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="3">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/image1"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/image2"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:id="@+id/image3"/>

</LinearLayout>

答案 1 :(得分:0)

设置layout_weight =&#34; 1&#34;你的三个ImageViews。将layout_width设置为match_parent,将layout_height设置为0dp。

相关问题