ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

如何RTL这个Android布局?

2019-07-28 10:33:10  阅读:310  来源: 互联网

标签:android android-layout right-to-left


我想在Android中布局下面的rtl(从右到左)就像在父布局中使用layoutDirection =“rtl”(但它仅适用于4.2和更高版本)以及任何方式使其明确地从右向左.
这是主要的android项目布局的一部分,用于Android中的Preference Activity.

<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2006 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
Layout for a Preference in a PreferenceActivity. The
Preference is able to place a specific widget for its particular
type in the "widget_frame" layout.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/selectableItemBackground"
    android:gravity="center_vertical"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:paddingEnd="?android:attr/scrollbarSize" >

    <ImageView
        android:id="@+android:id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center" />

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="6dip"
        android:layout_marginEnd="6dip"
        android:layout_marginStart="15dip"
        android:layout_marginTop="6dip"
        android:layout_weight="1" >

        <TextView
            android:id="@+android:id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:fadingEdge="horizontal"
            android:singleLine="true"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+android:id/summary"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignStart="@android:id/title"
            android:layout_below="@android:id/title"
            android:maxLines="4"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="?android:attr/textColorSecondary" />
    </RelativeLayout>
    <!-- Preference should place its actual preference widget here. -->

    <LinearLayout
        android:id="@+android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:orientation="vertical" />

</LinearLayout>

(抱歉我的英语不好!!)

解决方法:

不幸的是,Android 4.2(API级别17)或更高版本仅支持RTL布局支持功能.对于之前的版本,您可以为RTL布局添加布局文件夹.例如,在布局文件夹中放置LTR版本文件布局,在layout-ldrtl文件夹中放置RTL版本文件布局.

至于改变什么来制作RTL取决于你想在RTL中做多少.因为视图的某些部分将保留在同一侧(如导航栏),除非您自定义它.您将需要查看和更改应更改的内容以使其更酷的视图.例如,在LTR视图中,我们可以说:

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="left" 
    android:orientation="horizontal"
    android:paddingLeft="8dp"
    android:paddingRight="4dp">
</LinearLayout>

然后在RTL视图中你会像这样:

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="left" 
    android:orientation="horizontal"
    android:paddingLeft="4dp"
    android:paddingRight="8dp">
</LinearLayout>

你可以看到我们已经改变了android中的填充:paddingLeft =“4dp”和android:paddingRight =“8dp”但是我们保留了android:layout_gravity =“left”因为它应该像这种情况一样(也许在另一个视图将是android:layout_gravity =“right”).

作为现实生活中的示例,您可以比较Android Quran应用程序RTL audio_panelLTR audio_panel的两个视图.

标签:android,android-layout,right-to-left
来源: https://codeday.me/bug/20190728/1560513.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有