我是设计android的新手,所以我希望我的主屏幕图像适合所有设备,我希望这个MainScreen页面适合所有设备。它有3个我已经给予重量的图像但是如果我在标签上测试它似乎没有任何效果。它不是我想要的方式,这是图像
这是我的XML。我知道我不应该为高度提供dp但是如何在不给出尺寸的情况下使它看起来像那样。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.zeba.broccoli.MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginTop="50dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<ImageView
android:id="@+id/ms1"
android:layout_width="match_parent"
android:layout_height="374dp"
android:layout_weight="7"
android:scaleType="fitXY"
android:src="@drawable/avatar" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<ImageView
android:id="@+id/ms2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/ee"
android:layout_weight=".5" />
<ImageView
android:id="@+id/ms3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@drawable/dd"
android:layout_weight=".5" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
答案 0 :(得分:1)
使用此代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7">
<ImageView
android:id="@+id/ms1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3">
<ImageView
android:id="@+id/ms2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".5"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" />
<ImageView
android:id="@+id/ms3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight=".5"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
希望这会对你有所帮助
答案 1 :(得分:1)
请参阅以下xml解决方案以获取所需内容。
您始终可以通过播放layout_weight参数来更改每个视图元素的相对宽度和高度。它的宽度/高度为百分比:
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@android:drawable/btn_default"
android:scaleType="fitXY"
android:layout_weight="70"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="30">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/btn_default"
android:scaleType="fitXY"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@android:drawable/btn_default"
android:scaleType="fitXY"
android:layout_weight="1"/>
</LinearLayout>