如何在底部对齐RecyclerView中textview的文本
我正在创建一个文本大小 UI 列表,该列表将在 RecyclerView
中呈现相同文本的不同大小。
要求是,在 RecyclerView 中渲染的文本项应从视图底部渲染,但从顶部渲染。这是我的代码:
RecyclerView声明:
<RelativeLayout
android:id="@+id/sizes_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:elevation="30dp"
android:paddingVertical="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:id="@+id/size_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/subtitles"
android:layout_gravity="center_horizontal"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<TextView
android:id="@+id/size_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="16dp"
android:gravity="center_vertical"
android:minWidth="50dp"
android:text="@string/size"
android:textColor="@color/white"
android:textStyle="bold"
tools:textColor="@color/black" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/text_track_size_list_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/size_textview"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</RelativeLayout>
</RelativeLayout>
查看项目声明:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/focus_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp">
<TextView
android:id="@+id/row_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:paddingHorizontal="10dp"
android:paddingVertical="7dp"
android:textAllCaps="false"
android:textColor="@drawable/text_size_color"
tools:text="Aa" />
</FrameLayout>
绑定视图持有者方法:
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val textSizeOption: TextSizeOption = extSizeOptions[position]
holder.focusView.tag = textSizeOption
holder.rowItem.textSize = textSizeOption.fontSize
if(mSelectedFormat != null && mSelectedFormat == textSizeOption.id) {
holder.focusView.isSelected = true
} else {
holder.focusView.isSelected = (position == 0 && mSelectedFormat == null)
}
}
我尝试了多种方法,例如将项目视图包装在相对布局中并给出alignParentBottom等,但效果不佳。
这是它现在的样子的屏幕截图: 大小文本顶部对齐
即使大小标签也没有像代码中给出的那样居中对齐。不确定我是否遗漏了什么,但任何帮助将不胜感激
I am creating a list of text sizes UI that will have the different sizes of the same text rendering in the RecyclerView
.
The requirement is, the text item that is rendering in the RecyclerView shall render from the bottom of the view, but its rendering from the top. Here is my code:
RecyclerView declaration:
<RelativeLayout
android:id="@+id/sizes_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:elevation="30dp"
android:paddingVertical="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:id="@+id/size_options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/subtitles"
android:layout_gravity="center_horizontal"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<TextView
android:id="@+id/size_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="16dp"
android:gravity="center_vertical"
android:minWidth="50dp"
android:text="@string/size"
android:textColor="@color/white"
android:textStyle="bold"
tools:textColor="@color/black" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/text_track_size_list_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@+id/size_textview"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</RelativeLayout>
</RelativeLayout>
View Item declaration:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/focus_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="10dp">
<TextView
android:id="@+id/row_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:paddingHorizontal="10dp"
android:paddingVertical="7dp"
android:textAllCaps="false"
android:textColor="@drawable/text_size_color"
tools:text="Aa" />
</FrameLayout>
Bind View Holder method:
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val textSizeOption: TextSizeOption = extSizeOptions[position]
holder.focusView.tag = textSizeOption
holder.rowItem.textSize = textSizeOption.fontSize
if(mSelectedFormat != null && mSelectedFormat == textSizeOption.id) {
holder.focusView.isSelected = true
} else {
holder.focusView.isSelected = (position == 0 && mSelectedFormat == null)
}
}
I have tried multiple things like wrapping the item view in the Relative Layout and giving alignParentBottom, etc but that didn't work as well.
Here is the screenshot of how it's looking right now:
Sizes text top aligning
Even the Size label is not centre aligning as it's given in the code. Not sure if I am missing something, but any help will be super appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样修改您的视图项目将解决您的问题
Modifying your view item like this will solve your problem