【发布时间】:2020-06-02 09:55:17
【问题描述】:
我正在处理底部工作表对话框,想知道如何将所有 3 个文本视图对齐到中心以及将它们与相同的左边距对齐。请注意,所有 3 行的 textview 还留有一个 imageview(这里 3 行是重命名、共享和删除)。 重心使它们与中心对齐,但它们的左边距不会相同。我希望他们的左边距也一样
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="@+id/btmsheet"
android:background="@color/white"
android:layout_marginLeft="@dimen/pad_5dp"
android:layout_marginRight="@dimen/pad_5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:id="@+id/dragView"
android:layout_marginTop="@dimen/pad_10dp">
<View
android:layout_width="@dimen/pad_50dp"
android:layout_height="@dimen/pad_5dp"
android:background="@color/grey_color" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp">
<TextView
android:id="@+id/bottom_sheet_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="@dimen/text_20sp"
android:textColor="@color/black"
android:text=""
tools:text="RB000019.JPG"
android:textStyle="bold"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#E5E5E5" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:id="@+id/lyt_duplicate"
android:orientation="horizontal"
android:padding="15dp"
>
<TextView
android:id="@+id/bottom_sheet_rename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/edit"
android:drawablePadding="@dimen/pad_15dp"
android:paddingStart="@dimen/pad_20dp"
android:text="@string/rename_project_name"
android:textColor="@color/black"
android:textSize="@dimen/text_16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#E5E5E5" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:id="@+id/lyt_rename"
android:orientation="horizontal"
android:padding="15dp"
android:gravity="center_horizontal|center_vertical">
<TextView
android:id="@+id/bottom_sheet_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/text_16sp"
android:textColor="@color/black"
android:text="@string/share_project"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:drawableStart="@drawable/ic_share"
android:drawablePadding="@dimen/pad_15dp"/>
</android.support.constraint.ConstraintLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#E5E5E5" />
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:padding="15dp"
android:id="@+id/lyt_move"
android:gravity="center_horizontal|center_vertical">
<TextView
android:id="@+id/bottom_sheet_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/text_16sp"
android:textColor="@color/black"
android:text="@string/delete_project"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:drawableStart="@drawable/delete"
android:layout_marginStart="@dimen/pad_5dp"
android:drawablePadding="@dimen/pad_20dp"
/>
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</LinearLayout>
【问题讨论】:
-
这 3 行看起来像这样,因为
ImageViews 在它们的左侧,您可能将整个View居中(文本 + 图标)。它们只是看起来像不以中心为中心,但实际上是。如果您仅将TextViews 水平居中并将ImageViews 放在它们的左侧(在XML 中),它应该可以完成这项工作。 -
我已添加代码请检查
-
哦,我明白了。您正在通过
drawableStart在TextView中实现它。尝试删除drawableStart参数,而不是将ImageView放在TextView的左侧以表示您的drawable,然后仅居中TextView。 -
@SkypeDogg 您所说的将使所有文本居中,但是所有这 3 个文本视图的左边距是否相同?我希望它们都具有相同的左边距和一点中心
-
请检查我的问题标题
标签: android uitextview bottom-sheet margins