[英]Background with a percentage in Android Layout
我想要实现的是,我想绘制一个包含文本的框。 背景颜色将填充包装的百分比,该百分比将是一个变量。
如何在 Android 布局中实现这一点?
(如果这是一个 HTML 项目,我将设置两个 div(父/子):父将是相对的,子将是绝对的。所以我会将子 div 定位在底部并将高度设置为百分比。)
您可以使用 ConstraintLayout 并将textView
的app:layout_constraintHeight_percent
设置为 0 到 1 之间的任何值。
<androidx.constraintlayout.widget.ConstraintLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:textSize="64sp"
android:gravity="center_horizontal"
android:text="Text"
app:layout_constraintBottom_toBottomOf="parent"
android:background="#f9d048"
app:layout_constraintHeight_percent=".5"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.