简体   繁体   English

如何在另一个视图基线的中间对齐视图?

[英]How to align views in the middle of another views baseline?

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. 我认为最好用我想在android中创建的UI图片来解释。

替代文字

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>

@pengwang and to whom it may concern @pengwang和它可能关心的人

baseline refers to line at base of any view, buttons, imageviews, or any controls. baseline指的是任何视图,按钮,图像视图或任何控件的基线。 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. 当您使用基线属性时,您将给出您想要引用的基数的任何ID,或者您想要按钮或任何地方的ID。 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>

do something like this 做这样的事情

    <EditText
        android:id="@+id/searchedittext"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:hint="Search Events, Restaurants, Businesses"
        android:singleLine="true"
        android:textSize="15dip" />

    <Button
        android:id="@+id/searchbtn"
        android:layout_width="40dip"
        android:layout_height="40dip"
        android:layout_marginLeft="-50dip"
        android:background="@drawable/ic_menu_search" />
    <Button
        android:id="@+id/searchbtn2"
        android:layout_width="40dip"
        android:layout_height="40dip"
        android:layout_marginLeft="-30dip"
        android:background="@drawable/ic_menu_search" />
</LinearLayout>

要放置父视图的视图中心,只需指定此属性android:gravity =“center”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM