簡體   English   中英

ConstraintLayout 如何與屏幕中心對齊而不重疊不均勻的側邊按鈕

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM