在我的布局中,我有一个 ConstraintLayout
包含两个 TextView
元素。它们目前大小相同,但我希望它们具有不同的重量,比例为 6:4
。
这如何在我的 ConstraintLayout
中实现?
原文由 Prashant Jajal 发布,翻译遵循 CC BY-SA 4.0 许可协议
在我的布局中,我有一个 ConstraintLayout
包含两个 TextView
元素。它们目前大小相同,但我希望它们具有不同的重量,比例为 6:4
。
这如何在我的 ConstraintLayout
中实现?
原文由 Prashant Jajal 发布,翻译遵循 CC BY-SA 4.0 许可协议
经过一些研究,我找到了其他具有指南视图的解决方案。
<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white">
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/green_color"
android:fontFamily="@font/overpass_light"
android:textAllCaps="true"
android:textColor="@color/dark_grey_button"
android:textSize="@dimen/h5"
app:layout_constraintEnd_toStartOf="@+id/guideline"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:id="@+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/grey_text"
android:fontFamily="@font/overpass_light"
android:textAllCaps="true"
android:textColor="@color/dark_grey_button"
android:textSize="@dimen/h5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guideline"
app:layout_constraintTop_toTopOf="parent"/>
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.6"
/>
</android.support.constraint.ConstraintLayout>
原文由 Prashant Jajal 发布,翻译遵循 CC BY-SA 3.0 许可协议
1 回答1.2k 阅读✓ 已解决
1 回答2k 阅读
1 回答1.1k 阅读
1 回答991 阅读
1 回答948 阅读
1 回答901 阅读
1 回答904 阅读
在 XML 中
创建水平链,然后使用
app:layout_constraintHorizontal_weight
属性:在爪哇
创建您的视图并将它们添加到父
ConstraintLayout
。您将需要给他们每个人一个id
以便一切正常;您可以使用View.generateViewId()
或者您可以为它们定义一个id
资源。然后创建一个
ConstraintSet
对象并创建你的链: