Android按钮将图像放在中间,文本放在底部

Android按钮将图像放在中间,文本放在底部,android,image,button,text,center,Android,Image,Button,Text,Center,我想把图像放在中间,然后在按钮的正下方放置文本,我试图设置android:gravity,但无法正确设置,下面是附加的图像: 下面是我的xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:la

我想把图像放在中间,然后在按钮的正下方放置文本,我试图设置android:gravity,但无法正确设置,下面是附加的图像:

下面是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="10.0dip" 
    android:paddingTop="10.0dip" 
    android:paddingRight="10.0dip" 
    android:paddingBottom="10.0dip"    
    android:background="@drawable/background_img"
    >

    <LinearLayout
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:paddingLeft="10.0dip" 
        android:paddingTop="10.0dip" 
        android:paddingRight="10.0dip" 
        android:paddingBottom="10.0dip"          
        >

        <Button          
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:id="@+id/button_listen"
            android:text="@string/listen"
            android:drawableTop="@drawable/listen_btn"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"      
            android:layout_gravity="center"
            />
        <Button
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:id="@+id/button_gallery"
            android:text="@string/gallery"
            android:drawableTop="@drawable/gallery_btn"
            android:layout_marginLeft="10dp"    
            android:layout_marginRight="10dp"    
            android:layout_marginTop="10dp"    
            android:layout_marginBottom="10dp"   
            android:layout_gravity="center"
            />
    </LinearLayout>
    <LinearLayout
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:paddingLeft="10.0dip" 
        android:paddingTop="10.0dip" 
        android:paddingRight="10.0dip" 
        android:paddingBottom="10.0dip"              
        >

        <Button
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:id="@+id/button_play"
            android:text="@string/play"                
            android:drawableTop="@drawable/play_btn"
            android:layout_marginLeft="10dp"
            android:layout_gravity="center"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            />
        <Button
            android:layout_height="match_parent"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:id="@+id/button_find"
            android:text="@string/find"
            android:drawableTop="@drawable/test_btn"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"    
            android:layout_marginBottom="10dp" 
            android:layout_gravity="center"
            />        
    </LinearLayout>
</LinearLayout>

将图像和文字居中的正确方法是什么


非常感谢。

试试这个,它对我有用

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="151dp"
        android:onClick="onClick"
        android:drawableTop="@drawable/ic_launcher"
        android:text="Button" />
</RelativeLayout>

我按照DjHacktorReborn的评论做了布局,这是冻结的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background_img"
    android:orientation="vertical" >
  <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical"
        android:weightSum="10" >    
      <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="4.1"
            android:orientation="vertical" >
        </LinearLayout>        
        <TableLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="2"
                android:orientation="horizontal"
                android:stretchColumns="*" >    
                 <TableRow android:layout_weight="1" >
                      <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >

                        <Button
                            android:id="@+id/button_listen"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_centerInParent="true"
                            android:background="@drawable/main_list"

                            android:paddingTop="90dp"



                            android:text="@string/listen"
                            android:textStyle="bold"
                            android:textColor="#FFFFFF" />

                        <ImageView
                            android:id="@+id/main_icon_content_image_view"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:src="@drawable/listen_btn" />
                    </RelativeLayout>
                     <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >

                        <Button
                            android:id="@+id/button_gallery"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="@drawable/main_list"

                            android:paddingTop="90dp"


                            android:text="@string/gallery"
                             android:textStyle="bold"
                            android:textColor="#FFFFFF" />

                        <ImageView
                            android:id="@+id/main_icon_schedule_image_view"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:src="@drawable/gallery_btn" />
                    </RelativeLayout>
                      </TableRow>
                      <TableRow android:layout_weight="1" >

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >

                        <Button
                            android:id="@+id/button_play"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="@drawable/main_list"
                            android:ellipsize="marquee"

                            android:paddingTop="90dp"


                            android:text="@string/play"
                             android:textStyle="bold"
                            android:textColor="#FFFFFF"
                             />

                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:src="@drawable/play_btn" />
                    </RelativeLayout>

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent" >

                        <Button
                            android:id="@+id/button_find"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="@drawable/main_list"

                            android:paddingTop="90dp"


                            android:text="@string/find"
                             android:textStyle="bold"
                            android:textColor="#FFFFFF" />

                        <ImageView

                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:src="@drawable/test_btn" />
                    </RelativeLayout>


                </TableRow>
    </TableLayout>                      
         <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="4.1"
            android:orientation="vertical" >
        </LinearLayout>        
</LinearLayout>
</LinearLayout>

这是更新的结果


感谢您的建议

尝试将按钮更改为LinearLayout,并在fakebutton上使用相同的onclicklistener

    <LinearLayout
        android:id="@+id/fakeButton"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center_vertical|center_horizontal"
        android:orientation="vertical" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon_big_evento" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/menu_about" />
    </LinearLayout>


所有4个按钮都是一样的?我试过其中一个按钮,它可以在所有4个按钮上工作,除非有其他问题