不会写骚年的代码 2022-04-07 14:33 采纳率: 77.8%
浏览 147
已结题

android 视图长度设置为match_parent导致溢出屏幕(fragment页面)

具体代码如下:

<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/background1">

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"
              android:orientation="vertical"
              tools:layout_editor_absoluteY="-99dp" tools:layout_editor_absoluteX="16dp">

    <LinearLayout android:layout_width="match_parent" android:gravity="center"
                  android:layout_height="0dp" android:orientation="horizontal"
                  android:layout_weight="0.7"
                  android:background="@color/ghostwhite">


        <ImageView android:layout_width="0dp"
                   android:layout_weight="1"
                   android:src="@mipmap/aixin"
                   android:layout_height="50dp"></ImageView>
        <EditText android:layout_width="0dp" android:layout_height="37dp"
                  android:layout_weight="4"
                  android:background="@drawable/yuan2"
                  android:hint="Q搜索" android:gravity="center"></EditText>
        <Button android:layout_width="0dp" android:layout_height="50dp"
                android:text="搜索" android:layout_weight="1.5"
                android:textColor="@color/black"></Button>
        <ImageView android:layout_width="0dp" android:layout_height="50dp"
                   android:layout_weight="1"
                   android:src="@mipmap/thetree"></ImageView>
        <ImageView android:layout_width="0dp" android:layout_height="50dp"
                   android:layout_weight="1"
                   android:src="@mipmap/liwuhe"></ImageView>
        <ImageView android:layout_width="0dp" android:layout_height="50dp"
                   android:layout_weight="1"
                   android:onClick="goliaotianshi"
                   android:src="@mipmap/xiaoxintubiao"></ImageView>
    </LinearLayout>

    <LinearLayout android:layout_width="match_parent" android:layout_height="0dp"
                  android:layout_weight="1"
                  android:background="@color/ghostwhite">
                        <TextView android:layout_width="0dp" android:layout_height="wrap_content"
                                  android:layout_weight="1"
                                  android:textSize="21dp" android:textColor="@color/black"
                                  android:text="火热话题"></TextView>
                        <TextView android:layout_width="0dp" android:layout_height="wrap_content"
                                  android:layout_weight="1" android:gravity="center"
                                  android:text="显示全部 >>" android:textColor="@color/black"
                                  android:textSize="13dp"></TextView>
    </LinearLayout>

    <LinearLayout android:layout_width="match_parent" android:layout_height="0dp"
                  android:layout_weight="1">
                    <ImageView android:layout_width="0dp" android:layout_height="match_parent"
                               android:layout_weight="4"
                               android:src="@mipmap/the_mian1"></ImageView>
    </LinearLayout>

    <LinearLayout android:layout_width="match_parent" android:layout_height="0dp"
                  android:layout_weight="1"
                  android:background="@color/ghostwhite">
                        <TextView android:layout_width="0dp" android:layout_height="20dp"
                                  android:layout_weight="1" android:gravity="center"
                                  android:textColor="@color/black" android:textSize="13dp"
                                  android:text="宠物创意乐园探索"></TextView>
                        <TextView android:layout_width="0dp" android:layout_height="20dp"
                                  android:layout_weight="1" android:gravity="center"
                                  android:textColor="@color/black" android:textSize="13dp"
                                  android:text="宠物摄影照片分享"></TextView>
                        <TextView android:layout_width="0dp" android:layout_height="20dp"
                                  android:layout_weight="1" android:gravity="center"
                                  android:textColor="@color/black" android:textSize="13dp"
                                  android:text="猫咪训练日常"></TextView>
    </LinearLayout>

    <LinearLayout android:layout_width="match_parent" android:layout_height="0dp"
                  android:layout_weight="1"
                  android:background="@color/ghostwhite">
                    <TextView android:layout_width="0dp" android:layout_height="wrap_content"
                              android:layout_weight="1"
                              android:textSize="21dp" android:textColor="@color/black"
                              android:text="知识问答"></TextView>
                    <TextView android:layout_width="0dp" android:layout_height="wrap_content"
                              android:layout_weight="1" android:gravity="center"
                              android:text="显示全部 >>" android:textColor="@color/black"
                              android:textSize="13dp"></TextView>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:layout_height="0dp"
                  android:layout_weight="1"
                  android:background="@color/ghostwhite">
                    <ImageView android:layout_width="0dp" android:layout_height="match_parent"
                               android:layout_weight="1"
                               android:src="@mipmap/the_main2"></ImageView>
    </LinearLayout>

    <LinearLayout android:layout_width="match_parent" android:layout_height="0dp"
                  android:layout_weight="1"
                  android:background="@color/ghostwhite">
                    <TextView android:layout_width="0dp" android:layout_height="20dp"
                              android:layout_weight="1" android:gravity="center"
                              android:textColor="@color/black" android:textSize="13dp"
                              android:text="宠物创意乐园探索"></TextView>
                    <TextView android:layout_width="0dp" android:layout_height="20dp"
                              android:layout_weight="1" android:gravity="center"
                              android:textColor="@color/black" android:textSize="13dp"
                              android:text="宠物摄影照片分享"></TextView>
                    <TextView android:layout_width="0dp" android:layout_height="20dp"
                              android:layout_weight="1" android:gravity="center"
                              android:textColor="@color/black" android:textSize="13dp"
                              android:text="猫咪训练日常"></TextView>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent" android:gravity="center"
                  android:layout_height="0dp" android:orientation="horizontal"
                  android:background="@color/ghostwhite" android:layout_weight="0.7">
    </LinearLayout>
</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

Design查看是这样的:

img

实际运行效果:

img

整个视图向右边溢出屏幕

  • 写回答

1条回答 默认 最新

  • 不会写代码的猴子 Android领域优质创作者 2022-04-07 16:21
    关注

    img


    都充满屏幕了,为什么还要偏移呢

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 4月15日
  • 已采纳回答 4月7日
  • 创建了问题 4月7日

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装
  • ¥40 复杂的限制性的商函数处理