我有一个列表视图,并显示在这样一个布局:
我希望该项目也被垂直居中。我能怎么做?这是code
< XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent>
<的TextView
机器人:ID =@ +的ListView / ID
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:layout_alignParentTop =真
机器人:layout_marginRight =24dp
机器人:文本=invisibile
机器人:能见度=水涨船高/>
<的TextView
机器人:ID =@ + ListView2 / X
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentTop =真
机器人:layout_centerHorizontal =真
机器人:layout_centerVertical =真
机器人:layout_marginTop =22dp
机器人:文本=TextView的
机器人:TEXTSIZE =24dp/>
< / RelativeLayout的>
解决方案
试试这个。这将会把相对布局内的文本视图垂直和水平。
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:重力=中心>
<的TextView
机器人:ID =@ + ID / some_id
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT/>
< / RelativeLayout的>
I have a listview and a layout that is displayed in this way:
I wish that the items were also centered vertically. How can I do? this is the code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+ListView/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="24dp"
android:text="invisibile"
android:visibility="gone" />
<TextView
android:id="@+ListView2/x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="22dp"
android:text="TextView"
android:textSize="24dp" />
</RelativeLayout>
解决方案
Try this. it will place the text view inside relative layout both vertically and horizontally.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<TextView
android:id="@+id/some_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>