我有阿拉伯语文本,因此我将重力设置为右侧以便从右侧开始文本。正文从现在开始。但另一个问题是文本从页面顶部开始渲染。但我需要将文本垂直居中。
尽管我尝试了几种变体,但我无法使其垂直居中。
这是我的 xml 文件的示例。
<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>
问题出在上面的文本视图上。
我在这里放置了整个 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>
谁能告诉我我哪里做错了?我想问题已经很清楚了。如果没有请在评论中告诉我。
在查看您的答案后,我附上了更新的代码。
<?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>
但我也处于同样的情况。没有文字垂直居中
您的 TextView 属性需要类似于,
<TextView ...
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|right" ../>
现在,描述为什么需要这样做,
android:layout_width="match_parent"
android:layout_height="match_parent"
使您的 TextViewmatch_parent
or fill_parent
如果你不想成为这样,match_parent
你必须给一些指定的值layout_height
这样它就有了垂直重心的空间。android:layout_width="match_parent"
必要的,因为它将您的 TextView 对齐在右侧,这样您就可以认识到 TextView 的父布局。
现在,它关于android:gravity
这使得您的 TextView 的内容对齐。android:layout_gravity
使 TextView 与其父布局对齐。
Update:
正如下面的评论说使用fill_parent
代替match_parent
。 (某些设备出现问题。)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)