I want to show a ImageButton aligned left and a TextView aligned center in the same layout. But both are ei开发者_如何转开发ther appearing at the center or left. I have tried LinearLayout and RelativeLayout. Please suggest me the solution. Many thanks in advance.
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_gravity="fill_horizontal" android:layout_width="fill_parent"
android:orientation="horizontal">
<TextView android:id="@+id/header_text1" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp" android:textStyle="bold" android:textColor="@color/white"
android:layout_marginLeft="70dp"
android:layout_centerHorizontal="true" android:layout_centerVertical="true"
android:singleLine="true" />
<ImageView android:src="@drawable/image_button1" android:id="@+id/back"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_toRightOf="@+id/header_text1" />
Use RelativeLayout and make use of android:layout_align="" parameters for your widgets (view element). There are align directives relative to parent view but also to other view elements.
精彩评论