如何将图像按钮高度设置为大于相对布局



我是Android的初学者,想为我的应用程序设计一个简单的页脚,为此编写以下xml代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/footer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:background="#125688"
    android:gravity="center">
    <ImageButton
        android:layout_width="45dp"
        android:layout_height="45dp"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/left"
        android:scaleType="fitCenter"
        android:layout_alignParentLeft="true"
        android:foregroundGravity="right"/>
</RelativeLayout>


一切都很好,但我希望图像按钮显示比相对布局框或页脚大一点,为了更解释我希望图像按钮高度大于布局,我该如何解决这个问题?谢谢。
我想要此输出,请单击:我的输出

你可以这样做,

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <RelativeLayout
        android:id="@+id/bottom_layout"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_alignParentBottom="true"
        android:background="@color/colorPrimary">

    </RelativeLayout>
    <ImageView
        android:id="@+id/profile__iv"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignTop="@+id/bottom_layout"
        android:layout_marginTop="-50dp"
        android:background="@drawable/bg_circle"/>
</RelativeLayout>

可绘制/bg_circle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="oval">
    <size
        android:width="60dp"
        android:height="60dp"/>
    <solid android:color="@color/White"/>
</shape>

不可能。因为 Imagebutton 是"相对布局"的子级。但是使用集两者的大小相等。

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/footer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:background="#125688"
android:gravity="center">
<ImageButton
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:src="@drawable/left"
    android:scaleType="fitCenter"
    android:layout_alignParentLeft="true"
    android:foregroundGravity="right"/>
</RelativeLayout>

或使用此

   <?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:orientation="vertical"
android:background="#B0BEC5"
tools:context="com.example.raj.jazzflurry.MainActivity">
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_menu_camera"
android:id="@+id/image"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@color/cardview_dark_background"
android:layout_alignParentBottom="true">
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_marginTop="20dp"
    android:textColor="#FFFFFF"
    android:text="Hai"
    android:textAlignment="center"/>
</RelativeLayout>
</RelativeLayout>

最新更新