Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align views in the middle of another views baseline?

Tags:

android

views

How do you align views relative to the "middle" part of another view?

I think it is best explained with a pic of the UI I'm trying to create in android.

alt text

like image 768
jonney Avatar asked Jun 16 '10 08:06

jonney


2 Answers

i usedthe follows code,but it still has some shortcomings: you should modify the value:

 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"

android:layout_gravity="center_horizontal|center_vertical"
>
<EditText 
    android:id="@+id/bullet"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"

    android:paddingRight="4dip"
    android:includeFontPadding="false"
    android:lines="4"
    android:text="hidhidihfidhfdifhdifhdifhidhfidf" />
<ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:background="#ffff00"
    android:src="@drawable/icon"
    android:layout_alignTop="@id/bullet"

     android:layout_marginLeft="50dip" />

  <ImageView
    android:id="@+id/icon1"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"

    android:background="#ff00ff"
    android:layout_alignBottom="@id/bullet"

    android:layout_marginLeft="100dip"
    android:src="@drawable/star_logo" />

  </RelativeLayout>
like image 199
pengwang Avatar answered Sep 17 '22 16:09

pengwang


@pengwang and to whom it may concern

baseline refers to line at base of any view, buttons, imageviews, or any controls. when you are using baseline property then you are giving any id of which base you want to refer or thats the place where you want your button or any. when you switch to graphical view it'll show how it adresses baseline for which you have defined

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <ImageButton
            android:id="@+id/iB"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher"
            android:layout_alignParentBottom="true" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button"
            android:layout_alignParentBottom="true"
            android:layout_toRightOf="@id/iB"
            android:layout_alignBaseline="@id/relativeLayout1" />
    </RelativeLayout>
</LinearLayout>
like image 33
JAaVA Avatar answered Sep 19 '22 16:09

JAaVA