伙计们。我正在学习 xamarin 并尝试为 android 制作一个基本的食物应用程序。这个应用程序是在 RTL 方向。现在我的主要内容中有一个 Listview,其中包含自定义布局列表。下面是这个自定义布局。我是 Xamarin Designer 窗口中的 RTL。
这是布局 asaml 代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layoutDirection="rtl"
android:textDirection="rtl">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2">
<ImageView
android:src="@drawable/rating4"
android:id="@+id/imgRating"
android:layout_width="70dp"
android:layout_height="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp" />
<ImageView
android:src="@drawable/defaultthumbnail"
android:id="@+id/imgThumbnail"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" />
<TextView
android:text="10,000 تومان"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:id="@+id/foodPrice"
android:layout_marginLeft="5dp"
android:textDirection="rtl" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="20dp">
<TextView
android:text="نام غذا"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtFoodName"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:text="توضیحات غذا"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:id="@+id/txtFoodDesc" />
<TextView
android:text="تاریخ"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/txtDate"
android:textSize="8sp"
android:textAllCaps="false" />
<TextView
android:text="آشپز"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtCook"
android:textSize="8sp"
android:textAllCaps="false" />
</LinearLayout>
这是我的主要布局,这个列表视图在其中。
<?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"
android:id="@+id/mainContentLayout"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_main"
android:layoutDirection="rtl"
android:textDirection="rtl">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainContentListView"
android:layoutDirection="rtl"
android:textDirection="rtl" />
</LinearLayout>
但是当我运行它时,这就是我得到的
正如您可以看到的那样,里面的 2 个线性布局遵循 RTL 规则,但被倒置了。