![](/img/trans.png)
[英]ConstraintLayout: center view on full screen but limit width to not overlap with side views
[英]ConstraintLayout how to align to center of screen and not to overlap uneven side buttons
您可以為此使用指南:
<?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.Guideline
android:id="@+id/guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.4"/>
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.6"/>
<View
android:layout_width="wrap_content"
android:layout_height="40dp"
android:background="@android:color/holo_blue_light"
app:layout_constraintEnd_toStartOf="@+id/guideline1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:layout_width="wrap_content"
android:layout_height="40dp"
app:layout_constraintStart_toEndOf="@id/guideline2"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:background="@android:color/holo_blue_light"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="sjkelf hue hwe fhwefh wehwe hwe hwef "
app:layout_constraintStart_toEndOf="@id/guideline1"
app:layout_constraintEnd_toStartOf="@id/guideline2"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
它看起來像這樣:
您好,對於這個問題,您應該將文本視圖的左側和右側與按鈕進行對比,並將 wrap_content 的高度的文本視圖大小設置為 0dp。
<TextView android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintStart_toEndOf="Left Button" app:layout_constraintEnd_toStartOf="Right Button" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.