繁体   English   中英

如何将图像按钮的高度设置为大于RelativeLayout?

[英]How can set Image Button height bigger than RelativeLayout?

我是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_c​​ircle.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>

暂无
暂无

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

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