文本视图中间的右对齐按钮 我想在Twitter视图中间对齐WhatsApp的右键。Android studio的布局预览屏幕显示右侧,但在手机上,它并没有对齐文本视图的中间,而是对齐屏幕的底部
单独使用片段没有问题,但当片段在活动中时,问题就出现了。我知道我的活动布局是错误的。 如何对齐发送按钮 Whatsapp按钮: Android Studio预览中的我的按钮: 手机上的我的按钮: 我的片段布局:文本视图中间的右对齐按钮 我想在Twitter视图中间对齐WhatsApp的右键。Android studio的布局预览屏幕显示右侧,但在手机上,它并没有对齐文本视图的中间,而是对齐屏幕的底部,android,android-layout,textview,android-xml,android-button,Android,Android Layout,Textview,Android Xml,Android Button,单独使用片段没有问题,但当片段在活动中时,问题就出现了。我知道我的活动布局是错误的。 如何对齐发送按钮 Whatsapp按钮: Android Studio预览中的我的按钮: 手机上的我的按钮: 我的片段布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorBlue"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/userNames"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:padding="10dp"
android:scrollbars="horizontal"
android:scrollHorizontally="true"
android:text="Hello Nilu Pilu"
android:textColor="@color/colorGreen" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:contentDescription="@null"
android:src="@drawable/ic_log_out" />
</RelativeLayout>
我的活动布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/colorPrimary"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
app:tabMode="scrollable">
<androidx.appcompat.widget.SearchView
android:id="@+id/search_action"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:contentDescription="@null"
android:iconifiedByDefault="false"
android:tint="@color/white"
app:defaultQueryHint="@string/searchForName"
app:iconifiedByDefault="false"
app:queryHint="@string/searchForName"
app:srcCompat="@drawable/ic_search_24" />
</androidx.appcompat.widget.Toolbar>
<LinearLayout
android:id="@+id/share_list_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="MergeRootFrame" />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
无需使用嵌套的
RelativeLayout
您只能使用单个RelativeLayout
使用RelativeLayout
输出
无需使用嵌套的
RelativeLayout
您只能使用单个RelativeLayout
使用RelativeLayout
输出
我建议使用
ConstraintLayout
布局,而不是RelativeLayout
,下面是使用ConstraintLayout
的代码,它将非常有效
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/emptyListColor"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/bottomView"
android:layout_height="0dp" />
<RelativeLayout
android:id="@+id/bottomView"
android:layout_width="match_parent"
android:layout_height="40dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
android:padding="5dp">
<TextView
android:id="@+id/userNames"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start|center_vertical"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:padding="5dp"
android:scrollbars="horizontal"
android:scrollHorizontally="true"
android:textColor="@color/white" />
</RelativeLayout>
<ImageView
android:id="@+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
app:layout_constraintTop_toTopOf="@+id/bottomView"
app:layout_constraintBottom_toTopOf="@+id/bottomView"
app:layout_constraintEnd_toEndOf="@+id/bottomView"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="@drawable/send_circle"
android:contentDescription="@null"
android:src="@drawable/attach_send2" />
</androidx.constraintlayout.widget.ConstraintLayout>
我建议使用
ConstraintLayout
布局而不是RelativeLayout
,下面是您使用ConstraintLayout
的代码,它将非常有效
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/emptyListColor"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/bottomView"
android:layout_height="0dp" />
<RelativeLayout
android:id="@+id/bottomView"
android:layout_width="match_parent"
android:layout_height="40dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
android:padding="5dp">
<TextView
android:id="@+id/userNames"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start|center_vertical"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:padding="5dp"
android:scrollbars="horizontal"
android:scrollHorizontally="true"
android:textColor="@color/white" />
</RelativeLayout>
<ImageView
android:id="@+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
app:layout_constraintTop_toTopOf="@+id/bottomView"
app:layout_constraintBottom_toTopOf="@+id/bottomView"
app:layout_constraintEnd_toEndOf="@+id/bottomView"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="@drawable/send_circle"
android:contentDescription="@null"
android:src="@drawable/attach_send2" />
</androidx.constraintlayout.widget.ConstraintLayout>
无法理解问题,我可以说,应用程序所做的是一个FAB按钮,您可以根据FAB按钮大小设置TextView的填充,您可以将箭头图像放置在TextView的左侧。无法理解问题,我可以说,WhatsApp做的是一个FAB按钮,你可以根据FAB按钮的大小设置TextView的填充,你可以将箭头图像放在TextView的左侧。单独使用片段没有问题,但当片段在活动中时,问题就发生了。我知道我的活动布局是错误的。请单独帮助meNo解决片段问题,但当片段在活动中时,问题就会出现。我知道我的活动布局是错误的。请单独帮助meNo解决片段问题,但当片段在活动中时,问题就会出现。我知道我的活动布局是错误的。请帮助我这是您的活动布局吗?是的,我添加了活动布局。我将Linearlayout从活动更改为RelativeLayout,并已修复。非常感谢单独使用片段并没有问题,但当片段在活动中时,问题就出现了。我知道我的活动布局是错误的。请帮助我这是您的活动布局吗?是的,我添加了活动布局。我将Linearlayout从活动更改为RelativeLayout,并已修复。非常感谢
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/emptyListColor"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/bottomView"
android:layout_height="0dp" />
<RelativeLayout
android:id="@+id/bottomView"
android:layout_width="match_parent"
android:layout_height="40dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
android:padding="5dp">
<TextView
android:id="@+id/userNames"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start|center_vertical"
android:ellipsize="end"
android:gravity="start|center_vertical"
android:maxLines="1"
android:padding="5dp"
android:scrollbars="horizontal"
android:scrollHorizontally="true"
android:textColor="@color/white" />
</RelativeLayout>
<ImageView
android:id="@+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
app:layout_constraintTop_toTopOf="@+id/bottomView"
app:layout_constraintBottom_toTopOf="@+id/bottomView"
app:layout_constraintEnd_toEndOf="@+id/bottomView"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="@drawable/send_circle"
android:contentDescription="@null"
android:src="@drawable/attach_send2" />
</androidx.constraintlayout.widget.ConstraintLayout>