[安卓/android/简式 android 开发教程 for xmppmini]等比例分配控件的占的宽度
clq
浏览(680) -
2021-02-09 13:17:20 发表
编辑
关键字: android_dev_self_book
[2021-02-09 17:05:48 最后更新]
[安卓/android/简式 android 开发教程 for xmppmini]等比例分配控件的占的宽度
在 css 中可以直接设置控件的宽度为 % 多少来完成。在 android 中本想用代码计算,不过使用下来实际上在 asd 界面设计器中就可以完成。
方法是设置
android:layout_weight="1"
这个数值相当于控件在父控件中等分宽度时的比重,就是说如果大家都是 1 那么大家宽度一样。 如果有一个 2 ,那么它占两宽度。稍有点绕。
示例:
<android.support.constraint.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="wrap_content"
android:background="@android:color/holo_orange_dark"
tools:context="net.newbt.xmppminiapplication.View_frmMain">
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="75dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="#FFFFFF"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="好友"
tools:layout_editor_absoluteX="6dp"
tools:layout_editor_absoluteY="26dp" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
tools:layout_editor_absoluteX="12dp">
<TextView
android:id="@+id/btnFriend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="消息"
tools:layout_editor_absoluteX="18dp"
tools:layout_editor_absoluteY="26dp" />
</android.support.constraint.ConstraintLayout>
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
所在合集/目录
简式 android 开发教程 for xmppmini
更多
发表评论:
NEWBT官方QQ群1: 276678893
可求档连环画,漫画;询问文本处理大师等软件使用技巧;求档softhub软件下载及使用技巧.
但不可"开车",严禁国家敏感话题,不可求档涉及版权的文档软件.
验证问题说明申请入群原因即可.