Jonathan Star 2022-04-08 08:54 采纳率: 77.5%
浏览 27
已结题

请问Android 散乱的按钮如何布局

请问Android 散乱的按钮如何布局

想在这些图形上添加按钮,但是absoluteLayout在不同的机器上会偏,其他布局也想不出好办法
请在链接中看图

  • 写回答

3条回答 默认 最新

  • 俺不理解 2022-04-08 20:25
    关注

    ConstrainLayout 可以做到百分比定位宽高位置,应该可以满足你的需求

    示例代码:

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            xmlns:app="http://schemas.android.com/apk/res-auto">
    
        <androidx.constraintlayout.widget.ConstraintLayout
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                android:layout_width="match_parent"
                app:layout_constraintDimensionRatio="1.5"
                android:layout_height="0dp">
    
            <androidx.appcompat.widget.AppCompatImageView
                    android:src="@mipmap/img"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
    
            
    
            <View
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintHorizontal_bias="0.675"
                    app:layout_constraintVertical_bias="0.6"
                    android:background="@color/black"
                    app:layout_constraintHeight_percent="0.05"
                    app:layout_constraintWidth_percent="0.04"
                    android:layout_width="0dp"
                    android:layout_height="0dp"/>
    
        </androidx.constraintlayout.widget.ConstraintLayout>
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    效果:

    img

    切换屏幕比例后:

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

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

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧