2017-04-16 105 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」 –