【问题标题】:android - centre vertically and horizontally text with 2 buttons side-by-side beneathandroid - 垂直和水平居中文本,下方并排有 2 个按钮
【发布时间】:2012-06-05 18:36:59
【问题描述】:

我有意见。我希望图像徽标出现在布局的左上角和布局的中心(水平和垂直) 我希望文本下方有 2 个按钮(并排)的文本。这是我所拥有的,但它不起作用......有什么帮助吗?

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/linearlayout"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:fillViewport="true"
  android:background="@drawable/login_background"
>

<ImageView 
       android:id="@+id/imgLogo"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_x="-6px"
       android:layout_y="32px"
       android:background="@drawable/logo"
   />


  <RelativeLayout
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    >
             <TextView android:id="@+id/txt1"
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content" 
              android:text="Welcome to my app. Please select your language"      
              android:textColor="#FFFFFF"
              android:textSize="20sp"
              />

              <LinearLayout
            android:orientation="horizontal"
            android:background="@android:drawable/bottom_bar"
            android:paddingLeft="4.0dip"
            android:paddingTop="5.0dip"
            android:paddingRight="4.0dip"
            android:paddingBottom="1.0dip"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_below="@+id/TextView01"
            android:gravity="center"
            android:layout_centerInParent="true"
            >

                  <Button
                    android:id="@+id/btnEnglish"
                    android:layout_width="0.0dip" android:layout_height="fill_parent" 
                    android:text="English"
                    android:layout_weight="1.0"
                   /> 
                   <Button
                        android:id="@+id/btnSpanish"
                        android:layout_width="0.0dip" android:layout_height="fill_parent"
                        android:text="Spanish"
                        android:layout_weight="1.0"
                   /> 
            </LinearLayout>
</RelativeLayout>

【问题讨论】:

    标签: android layout button views


    【解决方案1】:

    我认为这是你想要的:

    <ImageView
        android:id="@+id/imgLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="-6px"
        android:layout_y="32px"
        android:background="@drawable/logo" />
    
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_centerVertical="true"
        android:gravity="center_vertical"
        android:layout_weight="1"
        android:orientation="vertical" >
    
        <TextView
            android:id="@+id/txt1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Welcome to my app. Please select your language"
            android:textColor="#FFFFFF"
            android:textSize="20sp" />
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/TextView01"
            android:layout_centerInParent="true"
            android:background="@android:drawable/bottom_bar"
            android:gravity="center"
            android:orientation="horizontal"
            android:paddingBottom="1.0dip"
            android:paddingLeft="4.0dip"
            android:paddingRight="4.0dip"
            android:paddingTop="5.0dip" >
    
            <Button
                android:id="@+id/btnEnglish"
                android:layout_width="0.0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1.0"
                android:text="English" />
    
            <Button
                android:id="@+id/btnSpanish"
                android:layout_width="0.0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1.0"
                android:text="Spanish" />
        </LinearLayout>
    </LinearLayout>
    

    【讨论】:

    • 非常感谢!效果很好!但是,我确实在 textview 中设置了重力=中心并将线性布局(用于按钮)更改为具有 width=fill_parent
    猜你喜欢
    • 2016-08-15
    • 1970-01-01
    • 2015-09-25
    • 2017-06-12
    • 2014-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-14
    相关资源
    最近更新 更多