波斯语布局在运行时和改变重力

时间:2016-06-05 07:06:17

标签: android layout persian

我开发了一个应用程序多语言英语和波斯语。在我的IDE(Android工作室)预览中,英文版面设计工作正常且完全相同。 但是,波斯语(波斯语)布局在运行时有问题,看起来不像我在IDE中准备的预览。我在Nexus S5-Samsung Galaxy S6中运行应用程序。 有没有人有想法? [This is English layout in IDE preview This is Farsi layout (layout-ar) This is what Farsi layout looks like in mobile device looks like its goes wrong 这个波斯语布局代码(layout-ar)     

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"  >
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/relativeLayout">


            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:padding="10dp"
                android:weightSum="10"
                android:id="@+id/op_successfulLayout"
                android:background="@drawable/layout_border_op_seccessful">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="5"
                    android:gravity="right"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:id="@+id/trx_result_tv" />

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/trx__result_img"
                    android:layout_weight="5"
                    android:src="@drawable/green_tick"/>

            </LinearLayout>



            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/op_successfulLayout"
                android:weightSum="10"
                android:padding="10dp"
                android:id="@+id/headerReceiptLayout">

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="5">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:text="@string/mabna_company_txt"
                        android:id="@+id/company_name_label"
                        android:textColor="@color/black"
                        android:gravity="center"
                        android:layout_gravity="center"
                        />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/mabna_number_txt"
                        android:layout_gravity="center"
                        android:id="@+id/mabna_number_tv" />
                </LinearLayout>

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/shaparak_img"
                    android:id="@+id/shaparak_img"
                    android:layout_weight="2"/>
            </LinearLayout>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="@string/receipt_balance"
                android:id="@+id/trx_type"
                android:textColor="@color/black"
                android:layout_weight="2"
                android:gravity="center"
                android:layout_below="@id/headerReceiptLayout"
                android:layout_gravity="center"/>
        </RelativeLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/relativeLayout"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:padding="10dp"
            >
            <LinearLayout
                android:id="@+id/receiptLayout"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:weightSum="10"
                    android:padding="5dp"
                    android:layout_marginTop="10dp"
                    >

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:id="@+id/postal_code_tv"
                        android:gravity="left"
                        android:layout_weight="5"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/postal_code_txt"
                        android:gravity="right"
                        android:layout_weight="5"
                        android:id="@+id/postal_code_label" />

                </LinearLayout>
                <View android:layout_width="wrap_content"
                    android:id="@+id/line_rec13"
                    android:layout_height="2dp"
                    android:background="@color/gray"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_above="@+id/connection_status"
                    >
                </View>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:weightSum="10"
                    android:padding="5dp"
                    android:layout_marginTop="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:id="@+id/contact_number_tv"
                        android:gravity="left"
                        android:layout_weight="5"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/contact_number_txt"
                        android:id="@+id/contact_number_label"
                        android:layout_weight="5"/>

                </LinearLayout>

                <View android:layout_width="wrap_content"
                    android:id="@+id/line_rec1"
                    android:layout_height="2dp"
                    android:background="@color/gray"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_above="@+id/connection_status"
                    >
                </View>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:weightSum="10"
                    android:padding="5dp"
                    android:layout_marginTop="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:id="@+id/merchant_name_tv"
                        android:layout_weight="5"
                        android:gravity="left"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/merchant_name_txt"
                        android:id="@+id/merchant_name_label"
                        android:layout_weight="5"
                        android:gravity="right"/>

                </LinearLayout>
                <View android:layout_width="wrap_content"
                    android:id="@+id/line_rec12"
                    android:layout_height="2dp"
                    android:background="@color/gray"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_above="@+id/connection_status">
                </View>
                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="right"
                    android:weightSum="10"
                    android:padding="5dp"
                    android:layout_marginTop="10dp">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:id="@+id/terminal_id_tv"
                        android:layout_weight="5"
                        android:gravity="left"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/terminal_number_txt"
                        android:id="@+id/terminal_id_label"
                        android:layout_weight="5"
                        android:gravity="right"/>
                </LinearLayout>
                <View android:layout_width="wrap_content"
                    android:id="@+id/line_rec5"
                    android:layout_height="2dp"
                    android:background="@color/gray"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_above="@+id/connection_status" >
                </View>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="right"
                    android:weightSum="10"
                    android:padding="5dp"
                    android:layout_marginTop="10dp">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:id="@+id/card_number_tv"
                        android:layout_weight="5"
                        android:gravity="left"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/card_number_txt"
                        android:id="@+id/card_number_label"
                        android:layout_weight="5"
                        android:gravity="right"/>
                </LinearLayout>
                <View android:layout_width="wrap_content"
                    android:id="@+id/line_rec6"
                    android:layout_height="2dp"
                    android:background="@color/gray"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_above="@+id/connection_status">
                </View>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:weightSum="10"
                    android:padding="5dp"
                    android:layout_marginTop="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:id="@+id/payment_type_tv"
                        android:layout_weight="5"
                        android:gravity="left"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/type_payment_txt"
                        android:id="@+id/payment_type_label"
                        android:layout_weight="5"
                        android:gravity="right"/>
                </LinearLayout>
                <View android:layout_width="wrap_content"
                    android:id="@+id/line_rec7"
                    android:layout_height="2dp"
                    android:background="@color/gray"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_above="@+id/connection_status" >
                </View>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:weightSum="10"
                    android:padding="5dp"
                    android:layout_marginTop="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:id="@+id/trace_number_tv"
                        android:layout_weight="5"
                        android:gravity="left"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/trace_number_txt"
                        android:id="@+id/trace_number_label"
                        android:layout_weight="5"
                        android:gravity="right"/>
                </LinearLayout>
                <View android:layout_width="wrap_content"
                    android:id="@+id/line_rec8"
                    android:layout_height="2dp"
                    android:background="@color/gray"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_above="@+id/connection_status" >
                </View>

                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:weightSum="10"
                    android:padding="5dp"
                    android:layout_marginTop="10dp">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:id="@+id/date_tv"
                        android:layout_weight="5"
                        android:gravity="left"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/payment_date"
                        android:id="@+id/date_label"
                        android:layout_weight="5"
                        android:gravity="right"/>
                </LinearLayout>
                <View android:layout_width="wrap_content"
                    android:id="@+id/line_rec9"
                    android:layout_height="2dp"
                    android:background="@color/gray"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_above="@+id/connection_status">
                </View>
                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:weightSum="10"
                    android:padding="5dp"
                    android:layout_marginTop="10dp">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:id="@+id/RRN_tv"
                        android:layout_weight="5"
                        android:gravity="left"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/RRN_txt"
                        android:id="@+id/RRN_label"
                        android:layout_weight="5"
                        android:gravity="right"/>
                </LinearLayout>
                <View android:layout_width="wrap_content"
                    android:id="@+id/line_rec4"
                    android:layout_height="2dp"
                    android:background="@color/gray"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_above="@+id/connection_status" >
                </View>
                <LinearLayout
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:weightSum="10"
                    android:padding="5dp"
                    android:layout_marginTop="10dp">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:id="@+id/payment_result_tv"
                        android:layout_weight="5"
                        android:gravity="left"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/payment_result_txt"
                        android:id="@+id/payment_result_label"
                        android:layout_weight="5"
                        android:gravity="right"/>
                </LinearLayout>
                <View android:layout_width="wrap_content"
                    android:id="@+id/line_rec11"
                    android:layout_height="2dp"
                    android:background="@color/gray"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_above="@+id/connection_status" >
                </View>
                <LinearLayout
                    android:id="@+id/shenase_qabzLayout"
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:weightSum="10"
                    android:padding="5dp"
                    android:layout_marginTop="10dp"
                    android:visibility="gone">
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:id="@+id/shenase_qabz_tv"
                        android:layout_weight="5"
                        android:gravity="left"/>
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/bill_id_txt"
                        android:id="@+id/shenase_qabz_label"
                        android:layout_weight="5"
                        android:gravity="right"/>
                </LinearLayout>
                <LinearLayout
                    android:id="@+id/shenase_pardakhtLayout"
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:weightSum="10"
                    android:padding="5dp"
                    android:layout_marginTop="10dp"
                    android:visibility="gone">

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:id="@+id/shenase_pardakht_tv"
                        android:layout_weight="5"
                        android:gravity="left"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:text="@string/payment_id_txt"
                        android:id="@+id/shenase_pardakht_label"
                        android:layout_weight="5"
                        android:gravity="right"/>
                </LinearLayout>
                <View android:layout_width="wrap_content"
                    android:id="@+id/line_rec10"
                    android:layout_height="2dp"
                    android:background="@color/gray"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp"
                    android:layout_above="@+id/connection_status" >
                </View>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textSize="30dp"
                    android:textStyle="bold"
                    android:layout_marginTop="10dp"
                    android:id="@+id/amount_recepit_tv"
                    android:layout_gravity="center"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:id="@+id/fail_opration_guide_tv"
                    android:text="@string/fail_opration_guide_txt"
                    android:layout_gravity="center"
                    android:gravity="center"
                    android:layout_margin="5dp"
                    android:visibility="invisible"/>
            </LinearLayout>
        </RelativeLayout>
    </RelativeLayout>
</ScrollView>

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:id="@+id/linearLayout3"
    android:weightSum="10">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:text="@string/screen_shot_txt"
        android:id="@+id/screen_shot_btn"
        android:layout_alignParentTop="true"
        style="?android:attr/borderlessButtonStyle"
        android:background="@color/blue_10"
        android:layout_centerHorizontal="true"
        android:textColor="@color/white"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:text="@string/confrim_txt"
        android:id="@+id/receipt_conf_btn"
        style="?android:attr/borderlessButtonStyle"
        android:background="@color/blue_10"
        android:layout_alignParentTop="true"
        android:textColor="@color/white"/>
</LinearLayout>

2 个答案:

答案 0 :(得分:1)

您应该使用重力“开始”和“结束”而不是“右”和“左”然后简单应用页面rtl选项

答案 1 :(得分:0)

当您将"right"属性设置为重力使用"end"时 设置"left"时也使用"start"

像这样:

android:gravity="right"
android:gravity="end"

如果这不起作用,请告诉我。 我有波斯语的自定义方法。