小编ham*_*ini的帖子

为api设置LayoutDirection(RTL)低于17

我打算建一个Persian app (RTL).我的应用程序包括ListView和导航抽屉.

Manifest在应用程序标签中添加了android:supportsRtl="true"

并在onCreate()方法中:getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

我知道,LayoutDirection不到17 api不起作用.

对于api等级17及更高:

在此输入图像描述

对于api低于17:

在此输入图像描述

我该如何解决这个问题.1-设置一个conditional statement检查android api并指定一个特定的布局?layout-ldrtleclipse中的2用文件夹?3 - ......?什么是最好的方法??

<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> …
Run Code Online (Sandbox Code Playgroud)

android right-to-left

30
推荐指数
1
解决办法
5700
查看次数

在状态设计模式中使用组合和实现

在这里阅读此链接,在此处输入链接描述,以了解State Desing Patern.

接口类:

public interface State {
    void doAction();
}
Run Code Online (Sandbox Code Playgroud)

onState类:

public class TVStartState implements State {

    @Override
    public void doAction() {
        System.out.println("TV is turned ON");
    }
}
Run Code Online (Sandbox Code Playgroud)

截止态:

public class TVStopState implements State {

    @Override
    public void doAction() {
        System.out.println("TV is turned OFF");
    }

}
Run Code Online (Sandbox Code Playgroud)

TvContext类:

public class TVContext implements State {

    private State tvState;

    public void setState(State state) {
        this.tvState=state;
    }

    public State getState() {
        return this.tvState;
    }

    @Override
    public void doAction() { …
Run Code Online (Sandbox Code Playgroud)

java oop design-patterns object-composition implements

3
推荐指数
1
解决办法
143
查看次数