首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何避免线性布局中不必要的相对布局

如何避免线性布局中不必要的相对布局
EN

Stack Overflow用户
提问于 2022-11-03 21:11:39
回答 1查看 38关注 0票数 1

我使用线性布局来显示一个ImageView,并使它只显示屏幕的一半。我所做的就是在这个线性布局中添加一个相对的布局,这样这个ImageView只占据屏幕的一半。我收到了一个警告,因为它是正常的,因为这个相对布局没有任何孩子,但我使用它只占据另一半的屏幕。我如何才能避免这个警告而产生同样的结果呢?

这就是我所拥有的:

代码语言:javascript
运行
复制
 <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" >
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-11-04 09:59:23

使用下面的代码,imageView只占屏幕的一半:

代码语言:javascript
运行
复制
<?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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74309608

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档