Android 改造TikTok';s注释界面:底部的粘性编辑文本
问题:我正在尝试使用Android 改造TikTok';s注释界面:底部的粘性编辑文本,android,android-recyclerview,android-edittext,Android,Android Recyclerview,Android Edittext,问题:我正在尝试使用BottomSheetDialogFragment和RecyclerView重新制作TikTok的评论UI 这是它的样子(原版): 这就是我现在尝试的:基本上,我有一个FrameLayour,它的第一个子元素包含除EditText之外的所有东西,第二个子元素当然是EditText <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http:/
BottomSheetDialogFragment
和RecyclerView
重新制作TikTok的评论UI
这是它的样子(原版):
这就是我现在尝试的:基本上,我有一个FrameLayour,它的第一个子元素包含除EditText之外的所有东西,第二个子元素当然是EditText
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/no_of_comments"
android:layout_width="match_parent"
android:layout_height="36dp"
android:text="30.8k comments"
android:gravity="center_vertical|center_horizontal"
android:textColor="@color/darkGreyText" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="300dp">
<androidx.recyclerview.widget.RecyclerView
tools:listitem="@layout/item_comment"
android:id="@+id/comments_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:layout_gravity="bottom"
>
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_edit_text"
android:hint="Leave a comment"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textSize="12sp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/bleh"
android:background="@android:color/white"
android:alpha="0.3"
android:layout_alignParentRight="true"
android:hapticFeedbackEnabled="true"
/>
</RelativeLayout>
</FrameLayout>
只需使用线性布局作为根,并将权重应用于循环视图
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/no_of_comments"
android:layout_width="match_parent"
android:layout_height="36dp"
android:text="30.8k comments"
android:gravity="center_vertical|center_horizontal"
android:textColor="@color/darkGreyText" />
<androidx.recyclerview.widget.RecyclerView
tools:listitem="@layout/item_comment"
android:id="@+id/comments_list"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:layout_gravity="bottom"
>
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border_edit_text"
android:hint="Leave a comment"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textSize="12sp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/bleh"
android:background="@android:color/white"
android:alpha="0.3"
android:layout_alignParentRight="true"
android:hapticFeedbackEnabled="true"
/>
</RelativeLayout>
</LinearLayout>
您可以在回收视图的底部添加一个填充,使其始终位于编辑文本的顶部。这样一来,EditText
就显得“粘性”了,RecyclerView
就不会被EditText
覆盖了,你就不能在RecyclerView的底部添加一个填充,这样它就不会被EditText
覆盖,这样最后一个元素就不会被覆盖了吗?@jackz314完美。请随意添加这一点作为答案!我就这么做了。检查一下你要去的地方for@AbhishekSoni你尝试过我的答案吗?@Abhishek Soni如果我的答案对你有帮助,那么你可以投票接受我的答案,这样对其他有同样问题的人也会有帮助。太棒了!谢谢你的帮助。:)