我使用线性布局来显示一个ImageView,并使它只显示屏幕的一半。我所做的就是在这个线性布局中添加一个相对的布局,这样这个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" >发布于 2022-11-04 09:59:23
使用下面的代码,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://stackoverflow.com/questions/74309608
复制相似问题