【问题标题】:android rtl issue using v17 version layout使用 v17 版本布局的 android rtl 问题
【发布时间】:2020-04-29 20:49:02
【问题描述】:

我正在尝试在具有 imageView 和 textView 的布局中支持 rtl 视图(因此在 rtl 设备中,图像将位于文本的右侧,请参见下图)

为了实现这一点,我:

  • 创建了 v17 布局(见下文)。
  • 在清单中添加了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,但它对我没有用..

【问题讨论】:

  • 嗨,你找到答案了吗,我遇到了类似的问题。
  • 没有。我只是没有太多时间来解决这个问题,所以我只是以编程方式完成了它。我使用了这个函数:public static boolean isRTL(Context ctx) { Configuration config = ctx.getResources().getConfiguration(); return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; }

标签: android android-support-library right-to-left


【解决方案1】:

layoutDirection 设置为与textDirection 相对

一旦设置layoutDirectiontextDirection 相同

看看哪一个可以帮助你解决你的情况。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多