2017-04-16 100 views
0

我要支持“升”和“RTL”我的应用程序。 我已经测试我的应用程序的LTR和它的作品,但是当我测试的手机阿拉伯语对我的布局languague图像和文本分散修复布局变化的设备语言为阿拉伯语

问题

的图像和文本框在RTL被反转。 我想要的文本和图像的位置是一样的,在“LTR”

My layout.xml: 

    <?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:card_view="http://schemas.android.com/tools" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:cardBackgroundColor="@color/Grey_50" 
    app:cardCornerRadius="0dp" 
    app:cardUseCompatPadding="true" 
    card_view:cardCornerRadius="dp"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

       <ImageView 
        android:id="@+id/image_news" 
        android:layout_width="60dp" 
        android:layout_height="60dp" 
        android:layout_gravity="end" 
        android:layout_alignParentEnd="true" 
        android:layout_alignParentRight="true" 
        android:layout_centerHorizontal="true" 
        android:layout_centerVertical="true" 
        android:scaleType="fitXY" /> 

       <TextView 
        android:id="@+id/txt_news_title" 
        android:layout_width="match_parent" 
        android:layout_gravity="start" 
        android:layout_height="wrap_content" 
        android:layout_centerVertical="true" 
        android:layout_toLeftOf="@+id/image_news" 
        android:layout_marginRight="3dp" 
        android:textSize="13sp" /> 
       <View 
        android:id="@+id/view1" 
        android:layout_below="@+id/image_news" 
        android:layout_width="match_parent" 
        android:layout_height="1dp" 
        android:layout_marginTop="10dp" /> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="horizontal"> 

         <ImageView 
          android:id="@+id/recent" 
          android:layout_width="15dp" 
          android:layout_height="15dp" 
          android:layout_alignParentLeft="true" 
          android:layout_alignParentStart="true" 
          android:layout_alignParentTop="true" 
          android:layout_gravity="center" 
          android:layout_marginRight="2dp" 
          android:background="@drawable/ic_recent" 
          android:textAlignment="center" /> 

         <TextView 
          android:id="@+id/txt_timedate" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_alignParentTop="true" 
          android:layout_toEndOf="@+id/recent" 
          android:layout_toRightOf="@+id/recent" 
          android:text="20:49" 
          android:textColor="@color/Grey_600" 
          android:textSize="16sp" /> 
       </LinearLayout> 
     </RelativeLayout> 
</android.support.v7.widget.CardView> 

图像显示应用画面支撑LTR和RTL。 Image

+0

组布局方向。 – Nas

+0

@Nas哇它的作品!但他们说布局方向仅用于API 17及更高版本(当前最小值为16) 此警告消息是否会引起恐慌? –

回答

1

组布局方向替换您的XML代码LTR父布局

其从API级别17.如果你想为以前的API支持仅支持级别,你必须为阿拉伯语制作单独的XML布局文件。作为LTR父布局

+0

谢谢,但你可以给我一些文件或任何有关为阿拉伯文制作单独的XML文件? –

+0

检查这里https://mobikul.com/just-few-steps-to-make-your-app-rtl-supportable/ – Nas

+0

哇真棒@Nas只有一两件事,如果我会要问了一句: 我希望在活动启动..它之前它透明滑块说:喜欢不要忘记向下滑动以获取最新消息 –

0

与此

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:card_view="http://schemas.android.com/tools" 
    android:id="@+id/card_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:cardBackgroundColor="@color/Grey_50" 
    app:cardCornerRadius="0dp" 
    app:cardUseCompatPadding="true" 
    card_view:cardCornerRadius="dp"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layoutDirection="rtl"> 

     <ImageView 
      android:id="@+id/image_news" 
      android:layout_width="60dp" 
      android:layout_height="60dp" 
      android:layout_gravity="end" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_centerHorizontal="true" 
      android:layout_centerVertical="true" 
      android:scaleType="fitXY" /> 

     <TextView 
      android:id="@+id/txt_news_title" 
      android:layout_width="match_parent" 
      android:layout_gravity="start" 
      android:layout_height="wrap_content" 
      android:layout_centerVertical="true" 
      android:layout_toLeftOf="@+id/image_news" 
      android:layout_toStartOf="@+id/image_news" 
      android:layout_marginRight="3dp" 
      android:textSize="13sp" /> 
     <View 
      android:id="@+id/view1" 
      android:layout_below="@+id/image_news" 
      android:layout_width="match_parent" 
      android:layout_height="1dp" 
      android:layout_marginTop="10dp" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <ImageView 
       android:id="@+id/recent" 
       android:layout_width="15dp" 
       android:layout_height="15dp" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_alignParentTop="true" 
       android:layout_gravity="center" 
       android:layout_marginRight="2dp" 
       android:background="@drawable/ic_recent" 
       android:textAlignment="center" /> 

      <TextView 
       android:id="@+id/txt_timedate" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentTop="true" 
       android:layout_toEndOf="@+id/recent" 
       android:layout_toRightOf="@+id/recent" 
       android:text="20:49" 
       android:textColor="@color/Grey_600" 
       android:textSize="16sp" /> 
     </LinearLayout> 
    </RelativeLayout> 
</android.support.v7.widget.CardView> 
+0

对不起,它适用于android:layoutDirection =“ltr”不是android:layoutDirection =“rtl” –