关于按钮和图片的位置
我想知道怎么让按钮在图片的上层。就像PS的图层那样,最下层是一整张图片,然后上面有一个按钮。或者说是让不同的部件不在一个面上。我想知道这个可以实现么?注意:一定是通过添加ImageView添加的图片而不是给XML文件设置背景。感激大佬前来解答,如果还不明白的可以问我,随时解释!
献上来自萌新的敬意^_^
我想知道怎么让按钮在图片的上层。就像PS的图层那样,最下层是一整张图片,然后上面有一个按钮。或者说是让不同的部件不在一个面上。我想知道这个可以实现么?注意:一定是通过添加ImageView添加的图片而不是给XML文件设置背景。感激大佬前来解答,如果还不明白的可以问我,随时解释!
献上来自萌新的敬意^_^
2017-07-21
不是,我不懂 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>
这样..
<?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
我是这样写的,也可以实现
举报