android - How to make the center of a text of a child view is the center of its parent view? -
android - How to make the center of a text of a child view is the center of its parent view? -
as shown in pic below, want text of each button
centered, not in sense of that, text should started written center in sense of, center of text should center of view.
i used in xml file, gravity
property , layout_centerinparent="true"
well, see below, text started written center of view.
please allow me know property can job?
xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <edittext android:id="@+id/et_ip" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="ip address" /> <edittext android:layout_below="@+id/et_ip" android:id="@+id/et_port" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="1883" /> <button android:layout_below="@+id/et_port" android:id="@+id/bt_connect" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerinparent="true" android:text="connect..."/> <button android:layout_below="@+id/bt_connect" android:id="@+id/bt_clear" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerinparent="true" android:text="clear"/> <textview android:layout_below="@+id/bt_clear" android:gravity="center" android:id="@+id/tv_response" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerinparent="true" android:text="no_response"/> </relativelayout>
pic
i did center button on page , in view. here little illustration helpful.
<?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" > <linearlayout> <!-- add together other controls dont want buttons --></linearlayout> <linearlayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:paddingbottom="10dip" android:paddingleft="10dip" android:paddingright="10dip" android:paddingtop="10dip" android:layout_marginbottom="15dip" android:layout_gravity="bottom|center" android:layout_below="@id/login_form" > <button android:id="@+id/edit_button" style="@style/button.green" android:layout_width="133dp" android:layout_height="wrap_content" android:layout_marginleft="10dip" android:layout_marginright="10dip" android:layout_margintop="10dip" android:text="@string/ok" /> <button android:id="@+id/unlock_button" style="@style/button.green" android:layout_width="136dp" android:layout_height="wrap_content" android:layout_marginleft="10dip" android:layout_marginright="10dip" android:layout_margintop="10dip" android:text="@string/unlock" /> <button android:id="@+id/reset_password_button" style="@style/button.green" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="10dip" android:layout_marginleft="10dip" android:layout_marginright="10dip" android:text="@string/force_reset_password" /> </linearlayout> </merge>
merge great tool implement views/layouts if working in hierarchies. hope helps :)
android xml layout
Comments
Post a Comment