开发者

Alignment in Android

开发者 https://www.devze.com 2023-01-23 19:39 出处:网络
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 Relative

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号