Android Button Place Image in center and text at bottom

有些话、适合烂在心里 提交于 2019-12-03 23:57:32

Try this its work for me

<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>

Try change the button to LinearLayout and use same onclicklistener on fakebutton

    <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>

I followed DjHacktorReborn comments and made the layout, here is the freezed one

<?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>

Here is the updated result

Thanks for the suggestions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!