Tôi có văn bản arabic, do đó tôi đặt trọng lực sang phải để bắt đầu văn bản từ bên phải. Văn bản bắt đầu từ ngay bây giờ. Nhưng một vấn đề khác là văn bản bắt đầu hiển thị từ đầu trang. Nhưng tôi cần phải căn giữa theo chiều dọc của văn bản. Mặc dù tôi đã thử một số biến thể nhưng tôi không thể làm cho nó theo chiều dọc.cách căn chỉnh văn bản theo chiều dọc trung tâm trong android
Đây là mẫu tệp xml của tôi.
<LinearLayout
android:id="@+id/linearLayout5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="23dp"
android:gravity="right"
android:padding="@dimen/padding_maintextview"
android:text="@string/text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
</LinearLayout>
Sự cố với chế độ xem văn bản ở trên.
Ở đây tôi đã đặt toàn bộ tệp xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/page1background"
android:paddingRight="@dimen/padding_large" >
<TextView
android:id="@+id/textView1"
android:layout_width="196dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:paddingTop="@dimen/padding_Title_Top"
android:text="@string/text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<View
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="5dp" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/linearLayout2"
android:layout_below="@id/linearLayout1"
android:layout_gravity="center"
android:padding="@dimen/padding_maintextview" >
<LinearLayout
android:id="@+id/linearLayout5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginBottom="23dp"
android:gravity="right"
android:padding="@dimen/padding_maintextview"
android:text="@string/text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<View
android:id="@+id/view2"
android:layout_width="fill_parent"
android:layout_height="100dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<ImageButton
android:id="@+id/back_arrow"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginRight="45dp"
android:layout_weight=".5"
android:background="@drawable/backbut"
android:contentDescription="@string/Description"
android:onClick="onClickBtn"
android:src="@drawable/backarrowpress" />
<ImageButton
android:id="@+id/copyButton"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_weight=".5"
android:background="@drawable/copy"
android:contentDescription="@string/Description"
android:onClick="onClickBtn" />
</LinearLayout>
</RelativeLayout>
Ai có thể chỉ cho tôi nơi tôi đã phạm sai lầm không? Tôi nghĩ vấn đề là rõ ràng. Nếu không cho tôi biết trong bình luận.
Theo Thông tư này, tôi có mã được cập nhật được thêm vào sau khi xem lại câu trả lời của bạn.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/page1background"
android:paddingRight="@dimen/padding_large" >
<TextView
android:id="@+id/textView1"
android:layout_width="196dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:paddingTop="@dimen/padding_Title_Top"
android:text="@string/text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/textView1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<View
android:id="@+id/view1"
android:layout_width="fill_parent"
android:layout_height="5dp" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/linearLayout2"
android:layout_below="@id/linearLayout1"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:padding="@dimen/padding_maintextview" >
<LinearLayout
android:id="@+id/linearLayout5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:layout_marginBottom="23dp"
android:gravity="center_vertical|right"
android:padding="@dimen/padding_maintextview"
android:text="@string/text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<View
android:id="@+id/view2"
android:layout_width="fill_parent"
android:layout_height="100dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<ImageButton
android:id="@+id/back_arrow"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:layout_marginRight="45dp"
android:layout_weight=".5"
android:background="@drawable/backbut"
android:contentDescription="@string/Description"
android:onClick="onClickBtn"
android:src="@drawable/backarrowpress" />
<ImageButton
android:id="@+id/copyButton"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_marginLeft="45dp"
android:layout_weight=".5"
android:background="@drawable/copy"
android:contentDescription="@string/Description"
android:onClick="onClickBtn" />
</LinearLayout>
</RelativeLayout>
Nhưng tôi cũng ở trong tình huống tương tự. Không văn bản được theo chiều dọc làm trung tâm
Vui lòng tránh sử dụng 'match_parent'.Sử dụng fill_parent hoặc wrap_content thay thế.Bởi vì khớp _parent không hỗ trợ trong một số thiết bị. –
Tôi đã thử câu trả lời của bạn với match_parent và fill_parent vì ứng dụng của tôi hỗ trợ các phiên bản cũ hơn nhưng không có may mắn. Tôi vẫn phải đối mặt với cùng một vấn đề. Văn bản vẫn hiển thị ở trên cùng. – newday
Chỉ dành cho mục đích gỡ lỗi và kiểm tra, bạn có thể viết các giá trị mã hoá cứng tại LinearLayout 'android: layout_height =" 200dp "' cha mẹ của TextView. – user370305