[英]How can I locate TextView on center LinearLayout?
I am trying to locate TextView on center (vertical, horizontal) LinearLayout, but It does not work. 我正在尝试在中心(垂直,水平)LinearLayout上定位TextView,但是它不起作用。 I can locate only center horizontally or center on vertically, but i need locate center horizontally and center on vertically. 我只能水平放置中心或垂直居中,但是我需要水平放置中心和垂直居中。 Could you please explain how i can do this? 您能解释一下我该怎么做吗?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<LinearLayout
android:id="@+id/sigpanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/button_panel"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_alignParentStart="true"
android:baselineAligned="false"
android:background="@drawable/customborder"
android:orientation="vertical">
<TextView
android:id="@+id/tv_Signature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Signature"
android:layout_gravity="center"
android:textColor="#002060" />
</LinearLayout>
<LinearLayout
android:id="@+id/button_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/button_next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dip"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dip"
android:layout_weight="1"
android:background="@drawable/gradient_green"
android:drawableLeft="@drawable/ic_next"
android:gravity="center"
android:shadowColor="#014927"
android:shadowDx="0.0"
android:shadowDy="0.0"
android:shadowRadius="2.5"
android:text="Next"
android:textColor="#001B51"
android:textSize="20sp"
android:textStyle="bold" />
<Button
android:id="@+id/button_cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dip"
android:layout_marginRight="10dip"
android:layout_weight="1"
android:background="@drawable/gradient_red"
android:drawableLeft="@drawable/ic_cancel"
android:gravity="center"
android:shadowColor="#014927"
android:shadowDx="0.0"
android:shadowDy="0.0"
android:shadowRadius="2.5"
android:text="Clear"
android:textColor="#001B51"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
Add gravity center or center_vertical|clip_horizontal in LinearLayout
of TextView
as following: 添加重心或center_vertical |在clip_horizontal LinearLayout
的TextView
如下:
android:gravity="center"
OR 要么
android:gravity="center_vertical|clip_horizontal"
Example: 例:
<LinearLayout
android:id="@+id/sigpanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/button_panel"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_alignParentStart="true"
android:gravity="center"
android:baselineAligned="false"
android:background="@drawable/customborder"
android:orientation="vertical">
<TextView
android:id="@+id/tv_Signature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Signature"
android:layout_gravity="center"
android:textColor="#002060" />
</LinearLayout>
Hey use relative layout in linear or try this 嘿在线性中使用相对布局或尝试这个
android:id="@+id/tv_Signature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Signature"
android:gravity="center"
android:textColor="#002060"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.