Issue
I'm trying to achieve something like this! Alternative to check box How do I achieve this?
I tried creating a drawable with a central icon and a transparent background but the icon scales to fill the view when the drawable is set to the view foreground.
Also there is no support for setForground method for api level less than 23
I intend to achieve this dynamically when a view is clicked. Please help!!!
Solution
to achieve this view use relative layout like below code
<?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"
android:orientation="vertical">
<RelativeLayout
android:layout_width="90dp"
android:layout_height="120dp">
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/demo_img_4" />
<LinearLayout
android:id="@+id/transp_ll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#30000000"
android:gravity="center">
<ImageView
android:id="@+id/delete_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_delete_black_24dp" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//initialize views
setContentView(R.layout.activity_main);
image_view = findViewById(R.id.image_view);
delete_btn = findViewById(R.id.delete_btn);
transp_ll = findViewById(R.id.transp_ll);
//set transparent layout visibility gone
transp_ll.setVisibility(View.GONE);
//set click listener
image_view.setOnClickListener(this);
delete_btn.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.delete_btn:
//write here delete button click functionality..
transp_ll.setVisibility(View.GONE);
break;
case R.id.image_view:
transp_ll.setVisibility(View.VISIBLE);
break;
}
}
Answered By - Android Geek
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.