为了账号安全,请及时绑定邮箱和手机立即绑定

关于按钮和图片的位置

我想知道怎么让按钮在图片的上层。就像PS的图层那样,最下层是一整张图片,然后上面有一个按钮。或者说是让不同的部件不在一个面上。我想知道这个可以实现么?注意:一定是通过添加ImageView添加的图片而不是给XML文件设置背景。感激大佬前来解答,如果还不明白的可以问我,随时解释!



献上来自萌新的敬意^_^

正在回答

3 回答

不是,我不懂 Include :(

我用相对定位,button相对于imageView相对定位,比较简单。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="28dp"
        android:layout_marginTop="73dp"
        android:src="@android:drawable/btn_default_small" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/imageView1"
        android:layout_alignTop="@+id/imageView1"
        android:layout_marginLeft="58dp"
        android:layout_marginTop="70dp"
        android:text="Button" />

</RelativeLayout>

这样..


0 回复 有任何疑惑可以回复我~
#1

deemos 提问者

没法再回复里加代码,就自己回答了一下,可以看下。
2017-07-24 回复 有任何疑惑可以回复我~
<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/g04"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true" />

    <include
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        layout="@layout/layout01"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

上面是主要布局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:gravity="center_horizontal"
    android:orientation="vertical">

    <ToggleButton
        android:id="@+id/toggleButton"
        android:checked="true"
        android:textOn="@string/blu"
        android:textOff="@string/bac"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#9a000000"/>
</LinearLayout>

这是次要布局XML

我是这样写的,也可以实现

0 回复 有任何疑惑可以回复我~
#1

慕田峪630870

谢谢? 不过我还没学到include,等学到了在仔细看看,祝你学习进步?
2017-07-24 回复 有任何疑惑可以回复我~
#2

deemos 提问者 回复 慕田峪630870

谢啦,感觉include用起来更灵活一些
2017-07-24 回复 有任何疑惑可以回复我~

http://img1.sycdn.imooc.com//5971a08c0001fd0d02680314.jpg

是这样吗?

用 RelativeLayout 布局,很简单的

0 回复 有任何疑惑可以回复我~
#1

deemos 提问者

我刚刚研究出来了,使用Include写的,对吧?
2017-07-21 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Android攻城狮的第一门课(入门篇)
  • 参与学习       312506    人
  • 解答问题       4931    个

想快速掌握Android应用开发基础,选择学习这门课程就对了。

进入课程

关于按钮和图片的位置

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号