我正在尝试在具有imageView和textView的布局中支持rtl视图(因此在rtl设备中,图像将位于文本的右侧,请参见下图)
为了实现我:
android:supportsRtl="true"
布局代码:
<RelativeLayout
android:id="@id/asked_by_container"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="34dp"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="34dp"
android:layout_height="34dp"
android:id="@+id/profile_imageview"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:background="@drawable/question_profile_icon_corner_radius"
android:scaleType="centerCrop"
android:src="@drawable/anonprofile01" />
<com.theapp.widget.CustomTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/asked_textview"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/profile_imageview"
android:layout_marginStart="8dp"
android:textSize="14sp"
app:ttf_name="fonts/merriweather_sans/MerriweatherSans-Regular.otf"/>
</RelativeLayout>
<com.theapp.widget.CustomTextView
android:layout_below="@id/asked_by_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/question_textview"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:textSize="16sp"
android:layout_marginTop="4dp"
app:ttf_name="fonts/merriweather_sans/MerriweatherSans-Regular.otf"/>
预览显示它应该有效: android studio regular and rtl preview
确保我在保存RelativeLayout的适配器中添加了rootView.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
。
它没有用,所以我确保应用程序实际上是使用v17版本(通过在v17版本中添加一个虚拟按钮)..仍然无法工作..任何帮助?
我还检查了Force RTL layout direction not working for app,但这对我没用..
答案 0 :(得分:0)
将layoutDirection
设置为与textDirection
相反的位置
,然后将layoutDirection
设置为与textDirection
相同
看看哪种人可以帮助您解决您的情况。