Reputation: 1444
i want to make a button in another button , for example : we have 2 buttons : 1.imageButton (100 * 50)dp , 2.button (100 * 100)dp so my question is how can i put my imageButton inside my button ?
Upvotes: 0
Views: 1162
Reputation: 192
Set z-elevation property if you want the buttons to overlap and both needs to be visibile. android:elevation="2dp"
Upvotes: 0
Reputation: 5
Hope this may help you.. You should use Frame Layout for this. In XML file , do like this
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="100dp"
android:layout_height="100dp" />
<ImageButton
android:id="@+id/imagebutton"
android:layout_width="100dp"
android:layout_height="50dp"
android:src="@drawable/buttonsample"/>
</FrameLayout>
And now in java file, declare the instance of Button and ImageButton
ImageButton imagebutton;
Button button;
In onCreate() function of java class, do....
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
imagebutton = (ImageButton)findViewById(R.id.imagebutton);
button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do your stuff
}
});
imagebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do your stuff
}
});
}
Upvotes: 0
Reputation: 13343
You can use RelativeLayout
and just put second ImageButton
over first ImageButton
.
Update
Or You can use magrin
in LinearLayour
, for example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true" />
<ImageButton
android:layout_marginLeft="-100dp"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_alignParentTop="true" />
</LinearLayout>
Upvotes: 1