我正在使用線性布局來顯示 ImageView 并使其僅顯示螢屏的一半。我所做的就是在這個LinearLayout里面添加一個Relative布局,這樣這個ImageView就只占螢屏的一半。我收到一個警告,因為這是正常的,因為這個相對布局沒有任何孩子,但我只用它來占據螢屏的另一半。我怎樣才能得到相同的結果來避免這個警告?
這就是我所擁有的:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/img"
android:scaleType="fitXY"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
uj5u.com熱心網友回復:
使用下面的代碼,imageView 只是螢屏的一半:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@drawable/img"
android:scaleType="fitXY"
tools:ignore="ContentDescription" />
</LinearLayout>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/528318.html
標籤:安卓xml安卓布局布局
