Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

android - Set LayoutDirection (RTL) for api lower than 17

I am going to build a Persian app (RTL). my app includes a ListView and a Navigation Drawer .

I added in Manifest in application tag android:supportsRtl="true"

and in onCreate() method: getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

I know that LayoutDirection for less than 17 api does not work.

for api level 17 and higher:

enter image description here

for api lower than 17:

enter image description here

How do I solve this problem. 1- Putting a conditional statement to check the android api and assign a particular layout ? 2-use folder layout-ldrtl in eclipse? 3 - ... ? What is the best way??

<android.support.v4.widget.DrawerLayout

       xmlns:android="http://schemas.android.com/apk/res/android"

    android:id="@+id/drawer_layout"


    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/myback">



<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="40dp"  >


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginLeft="60dp"
        android:layout_marginRight="60dp"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="20dp" >




        <EditText
        android:id="@+id/edtxtsearch"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_gravity="center_horizontal"
         android:hint="????? ???? ?????"
          android:textSize="13dp"
         >

        <requestFocus />
    </EditText> 


        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_gravity="center"

            >


            <ListView
                        android:id="@+id/mylist"
                        android:layout_width="200dp"
                      android:layout_height="wrap_content"
                      android:layout_gravity="center_horizontal"
                      android:divider="@android:color/transparent"
                      android:dividerHeight="7dp"
                      android:scrollbarStyle="outsideInset"
                      />



           </LinearLayout>



</LinearLayout>




<FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

         >



    </FrameLayout>



     <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="wrap_content"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:background="#ffffff"
        android:dividerHeight="4dp"  
         android:divider="@android:color/transparent"     

       />

    </android.support.v4.widget.DrawerLayout>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

use ViewCompat from android.support.v4.view.ViewCompat !

like this :

ViewCompat.setLayoutDirection (View yourView, int layoutDirection)

layoutDirection is a constant from ViewCompat class


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...