首先我知道这个问题出现在此之前,但在尝试了很多之后我仍然没有成功.我从Android Developers网站开始研究这个例子 .
我正在尝试将菜单设置为从右到左打开,而不是在示例中如何实现(从左到右).此外,我想将打开菜单按钮移动到操作栏的右侧.我也在这里提出了一些答案,例如在这个答案中.
我尝试改变视图和布局的重力,但我得到错误:
没有抽屉视图发现绝对重力LEFT
你可以帮我弄清楚我的代码中有什么问题,为了设置菜单从右边打开,我应该改变什么,并将操作栏按钮移动到右侧?
xml代码在这里:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_gravity="right"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/content_frame"
android:layoutDirection="rtl"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<ListView android:id="@+id/left_drawer"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="10dp"
android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud) TextView始终存在RTL(从右到左)语言的问题.由于我只知道如何阅读希伯来语(除了英语),我将讨论它的问题:
文本对齐(我不是在谈论引力).作为一种RTL语言,希伯来语从右到左放置单词(与英语相反).
为了展示它是多么令人讨厌,想象一下,而不是展示"Hello world".你通常得到".Hello world".如果你只用一个句子就可以很容易地解决这个问题,但是当有多个标点字符时会更难.
元音位置.希伯来语不需要元音来阅读文本,但有时没有它们就很难阅读(特别是圣经).对于元音,希伯来语有所谓的"NIKUD",它实际上就像字母内部的点.Android中的问题是它们通常位于错误的位置.
为了展示它是多么令人讨厌,想象一下,而不是展示"Hello world".你通常得到".eHlol owrld".即使你试图修复它(把元音总是放在当前元素之后的一个字符),字母中的位置也不正确(想象"Hello"中的"e"就像"H"之上的那样,例子).
仅在版本4.2(在此处阅读,在"原生RTL支持"下),谷歌已经修复了所有希伯来语相关问题(或者至少看起来如此).
希伯来语的问题导致每个以色列航空公司和每个定制ROM制造商都有自己的解决方案来解决不同的问题,这使得在4.2之前的设备上处理RTL文本几乎是不可能的.
如果文本包括希伯来语和英文字母,事情会变得更加令人沮丧.
我已经阅读了很多关于这些问题的网站,我尝试了很多解决方案,没有一个解决了所有设备上的问题:
有人建议将字符'\ u200F'(或'\ u202D')放在文本的结尾/开始/两个位置.
有人建议使用Html.fromHtml()方法并在那里添加一些特殊内容.
有些人甚至建议使用WebView(也许使用WebSettings.setDefaultTextEncodingName()).
这个问题有一个明确的解决方案吗?
我认为最好的事情是因为Android 4.2解决了这个问题,并且Android是开源的,我们应该将其TextView导入到我们可以使用的库中,但谷歌还没有提供这样的库.
尝试将布局元素设置为RTL有序
在4.2及以上的行:layoutDirection="rtl"和清单:android:supportsRtl="true"工作得很好.
但是对于4.2以下它不是.
有人解决吗?
我使用NavigationView并添加工具栏与包括.我使用android:layoutDirection="rtl"和所有apis工作正常但在api 16它不起作用.
那我怎样才能在api 16中左到右工具栏?
drawer_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layoutDirection="rtl"
tools:openDrawer="end">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/appbar" />
<include
android:id="@+id/appbar"
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layoutDirection="rtl"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:elevation="0dp">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_main"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary" />
</android.support.design.widget.AppBarLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
MainActivity.java
Toolbar toolbar = (Toolbar) …Run Code Online (Sandbox Code Playgroud)