Android: How to avoid ImageView flashing when the screen is clicked? - android

I have an ImageView on the screen that I've scaled. When I click on the screen, the image goes back to its original size, and then the scaled size, and then back again constantly. Any ideas on how to fix this? Or why this is happening?
My code for the ImageView's fragment
public class LargeFragment extends Fragment {
Button back;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.large,container,false);
final ImageView p = (ImageView) view.findViewById(R.id.large);
final SharedPreferences pref = getActivity().getSharedPreferences("high",0);
p.setImageResource(getResources().getIdentifier(pref.getString("selectedPlayer","pink").concat("large"), "drawable",view.getContext().getPackageName()));
view.post(new Runnable() {
#Override
public void run() {
p.requestLayout();
final int w = view.getWidth();
p.getLayoutParams().height = w; //scaling the image here
}
});
back = (Button) view.findViewById(R.id.exit);
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LargeFragment.this.getActivity().finish();
}
});
return view;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
XML
<?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"
android:background="#drawable/bg2">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/large"
android:rotation="270"
android:scaleType="fitCenter"
android:layout_gravity="center_vertical"
/>
<Button
android:text="Button"
android:layout_width="wrap_content"
android:layout_gravity="end"
android:layout_height="35dp"
android:id="#+id/exit" />
</FrameLayout>

use android:scaleType in xml or ImageView.setScaleType() to scale the image. I think centerCrop is what you need.
see android:scaleType to get more information.

Related

onClickListener in Button doesn't work

I'm trying to display log value on the console, when I click on a Button inside a fragment. I don't know why but nothing happens when I click.
I tried by all possible ways (onClick directly on the layout, setOnClickListener extends OnClickListener, setting "clickable"=true).
Thank you for the help!
public class displayFacesFragment extends Fragment {
public static final String TITLE = "Faces";
public String selectedPeriod;
public Set<String> idFurnitures;
Button button75;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View inputFragmentView = inflater.inflate(R.layout.fragment_display_faces, container, false);
button75 =(Button) inputFragmentView.findViewById(R.id.button75);
button75.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
Log.d("Test", "onClickListener");
}
});
return inputFragmentView;
}
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/fragment_faces"
tools:context="com.example.haddad.managemyrounds.controller.fragment.displayFacesFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/hello_blank_fragment" />
<Button
android:id="#+id/button75"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</FrameLayout>

How to get the background color of a dialog fragment or window?

Red text came out a little small. Here is what it says:
Need to get the background color of the dialog so I can set the background of the "more info" textview to that same color. Need to do this programmatically because color of the dialog is different depending on API level.
Java code:
public class CityDetailDialog extends DialogFragment {
private SharedPreferences sharedPreferences;
private City mCity;
private LinearLayout mCityContainerLayout;
private ImageView mImageFlag;
private TextView mTextCity;
private ImageView mImageCity;
private ImageButton mButtonGoogleMaps;
private ImageButton mButtonWikipedia;
private TextView mMoreInfoTextView;
public CityDetailDialog() {
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container,
#Nullable Bundle savedInstanceState) {
sharedPreferences = getActivity().getSharedPreferences("settings", Context.MODE_PRIVATE);
return inflater.inflate(R.layout.dialog_city_detail, container, false);
}
#Override
public void onViewCreated(View view, #Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mCity = (City) getArguments().getSerializable("city");
mCityContainerLayout = (LinearLayout) view.findViewById(R.id.container_city_dialog);
mImageFlag = (ImageView) view.findViewById(R.id.flag_image);
mTextCity = (TextView) view.findViewById(R.id.city_name);
mImageCity = (ImageView) view.findViewById(R.id.city_image);
mButtonGoogleMaps = (ImageButton) view.findViewById(R.id.button_google_maps);
mButtonWikipedia = (ImageButton) view.findViewById(R.id.button_wikipedia);
mMoreInfoTextView = (TextView) view.findViewById(R.id.more_info_label);
mImageFlag.setImageResource(ResourceByNameRetriever.getDrawableResourceByName(mCity.
getCountryName(), getActivity()));
mTextCity.setText(ResourceByNameRetriever.getStringResourceByName(mCity.getCityName(),
getActivity()));
Picasso.with(getActivity()).load(mCity.getImageUrl()).into(mImageCity);
mButtonGoogleMaps.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent mapsIntent = new Intent(Intent.ACTION_VIEW);
mapsIntent.setData(Uri.parse("geo:" + mCity.getCoordinates()));
Intent chooser = Intent.createChooser(mapsIntent, getString(R.string.launch_maps));
startActivity(chooser);
}
});
mButtonWikipedia.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent wikiIntent = new Intent(Intent.ACTION_VIEW);
wikiIntent.setData(Uri.parse(mCity.getWikiUrl()));
Intent chooser = Intent.createChooser(wikiIntent, getString(R.string.launch_browser));
startActivity(chooser);
}
});
}
}
Based on the code in your xml file on github following changes need to be made to achieve the desired effect :
<LinearLayout
android:id="#+id/container_buttons"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="horizontal"
android:layout_below="#+id/relativeLayout">
.
.
.
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/relativeLayout">
<View
android:id="#+id/horizontal_divider1"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_centerInParent="true"
android:background="#color/gray"
android:layout_toLeftOf="#+id/more_info_label"
android:layout_toStartOf="#+id/more_info_label"/>
<TextView
android:id="#+id/more_info_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="5dp"
android:text="#string/more_info"
android:textSize="18dp" />
<View
android:id="#+id/horizontal_divider2"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_centerInParent="true"
android:background="#color/gray"
android:layout_toRightOf="#+id/more_info_label"
android:layout_toEndOf="#+id/more_info_label"/>
</RelativeLayout>

How to replace text of textView in fragment

I want to change a text of TextView on clicking a button. I have 2 buttons in my fragment and both have an onClick method for same TextView. Here is in detail what's happen in my fragment.
I set a default text to TextView means 1st text.
When 1st button clicked the 2nd text will appear on the TextView.
When 2nd button clicked again 1st text will appear on the TextView.
Here is my Fragment code
#Override
public void onCreate(Bundle savedInstanceState) {
Log.d("Rahul", "On Ganpati 1 fragment On Create ");
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d("Rahul", "On Ganpati 1 fragment On Create View ");
// Inflate the layout for this fragment
final TextView textView = (TextView)getView().findViewById(R.id.g1TextView);
textView.setText(getString(R.string.Ganpati_1));
Button marathi = (Button)getView().findViewById(R.id.g1Marathi);
marathi.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
textView.setText(getString(R.string.Ganpati_1));
}
});
Button english = (Button)getView().findViewById(R.id.g1English);
english.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
textView.setText(getString(R.string.GanpatiE));
}
});
return inflater.inflate(R.layout.fragment_ganpati_1, container, false);
}
Here is the XML file
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.lenovo.shopping.Shankar">
<Button
android:layout_width="168dp"
android:layout_height="50dp"
android:text="Left"
android:id="#+id/g1Marathi"
android:textAlignment="center"
android:layout_gravity="left|top" />
<Button
android:layout_width="168dp"
android:layout_height="50dp"
android:text="Right"
android:id="#+id/g1English"
android:textAlignment="center"
android:layout_gravity="right|top" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:paddingBottom="50dp"
android:id="#+id/scrollView"
android:layout_gravity="end|fill_vertical">
<TextView
android:id="#+id/g1TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/TextView" />
</ScrollView>
</FrameLayout>
When use Fragment, you need to override onCreateView and return View like this :
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_ganpati_1, null);
Log.d("Rahul", "On Ganpati 1 fragment On Create View ");
// Inflate the layout for this fragment
final TextView textView = (TextView)view.findViewById(R.id.g1TextView);
textView.setText(getString(R.string.Ganpati_1));
Button marathi = (Button)view.findViewById(R.id.g1Marathi);
marathi.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
textView.setText(getString(R.string.Ganpati_1));
}
});
Button english = (Button)view.findViewById(R.id.g1English);
english.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
textView.setText(getString(R.string.GanpatiE));
}
});
return view;
}

View centered on Preview but not on device

I am adding a fragment to an activity and it's layout is very simple:
<?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"
android:gravity="center_vertical"
android:padding="16dp">
<Button
android:id="#+id/fragment_pay_request_pbutton"
style="#style/ButtonsStyle"
android:text="Pay" />
<Button
android:layout_marginTop="16dp"
android:id="#+id/fragment_pay_request_rbutton"
style="#style/ButtonsStyle"
android:layout_below="#id/fragment_pay_request_pbutton"
android:text="Request" />
<Button
android:layout_marginTop="16dp"
android:id="#+id/fragment_pay_request_bbutton"
style="#style/ButtonsStyle"
android:layout_below="#id/fragment_pay_request_rbutton"
android:text="Bills" />
</RelativeLayout>
And all is ok on the preview:
But on device:
I'm using Lolipop 5.1 and overlay mode for testing layouts.
Has someone an idea why it doesn't work and what I could do to solve this kind of problem.
BTW: The fragment is very simple:
/**
* Created by laurentmeyer on 15/03/15.
*/
public class PayOrRequestFragment extends BaseFragment {
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View toReturn = inflater.inflate(R.layout.fragment_pay_request, container, false);
Button pay = (Button) toReturn.findViewById(R.id.fragment_pay_request_pbutton);
Button request = (Button) toReturn.findViewById(R.id.fragment_pay_request_rbutton);
configureButton(request, pay);
return toReturn;
}
private void configureButton(Button request, Button pay) {
request.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String[] parameters = {"com.payment.laurentmeyer.mobilepayment.fragments.ReceiveFragment", "com.payment.laurentmeyer.mobilepayment.fragments.RequestMethodsFragment"};
mCallbacks.createSliderWithParameters(parameters);
}
});
pay.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String[] parameters = {"com.payment.laurentmeyer.mobilepayment.fragments.SendFragment", "com.payment.laurentmeyer.mobilepayment.fragments.VerificationFragment"};
mCallbacks.createSliderWithParameters(parameters);
}
});
}
}
You must be putting the fragment into a view container in the Activity... You didn't post the layout for your Activity. Does your view container have android:layout_height="wrap_content"?

How to disable behind view click event Framelayout

Here i have one view pager activity which has one imageview and 2 overlay bars. there overlay bars i made using android xml file layout itself.
Here my requirement is like that
1) single tap on view pager's imageview first time = show top and bottom rectangle overlaybar.
2) single tap on view pager's imageview second time = hide these overlays.
These both are functions like android gallary view type.
But here when these top and bottom layout bar displays at that time i want to use only buttons click only which buttons are declare within this layout.
But I am not getting success to achieve this thing.
Problems
1) when top or bottom bar is there if i can click on next or previous button than its takes event for behind imageview single tap touch event, And my bar is getting invisible.
2) Only wants declare buttons event only
3) Avoid imageview getting clicked when i touch to overlay bar.
In short when my top and bottom image bar appears at that time no touh event takes place for imageview from top and bottom image bar. I can click on imageview but not making clickable when i click on actually next or previous or share button.
So these are the problems which i am facing, Please help me .
Source code :
activity_pager_image.xml
<?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" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<RelativeLayout
android:id="#+id/rl_top_overlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/slideshow_bar"
android:visibility="gone" >
<TextView
android:id="#+id/tv_top_overlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textIsSelectable="false" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_bottom_overlay"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#drawable/slideshow_bar"
android:visibility="visible" >
<Button
android:id="#+id/btn_left_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="35dp"
android:background="#drawable/ic_left_arrow" />
<Button
android:id="#+id/btn_below_share"
style="#style/normalText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="35dp"
android:background="#drawable/ic_share"
android:visibility="visible" />
<Button
android:id="#+id/btn_right_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="50dp"
android:layout_toRightOf="#id/btn_left_arrow"
android:background="#drawable/ic_right_arrow" />
</RelativeLayout>
</FrameLayout>
item_pager_image.xml
<?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" >
<demo.android.library.imagezoom.ImageViewTouch
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:contentDescription="#string/descr_image"
android:scaleType="fitXY" />
</FrameLayout>
JAVA code
public class ImagePagerActivity extends BaseActivity {
private static final String STATE_POSITION = "STATE_POSITION";
private DisplayImageOptions options;
private String[] imageUrls;
private ViewPager pager;
private static int sCounter = 0;
private RelativeLayout mRlTopOverlayBar = null;
private RelativeLayout mRlBottomOverlayBar = null;
private TextView mPageNumberText = null;
private Button mLeftArrow = null;
private Button mRightArrow = null;
int mPageCounter = 0;
int mTotalImages = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_pager);
mRlTopOverlayBar = (RelativeLayout) findViewById(R.id.rl_top_overlay);
mRlBottomOverlayBar = (RelativeLayout) findViewById(R.id.rl_bottom_overlay);
mPageNumberText = (TextView) findViewById(R.id.tv_top_overlay);
mLeftArrow = (Button) findViewById(R.id.btn_left_arrow);
mRightArrow = (Button) findViewById(R.id.btn_right_arrow);
Bundle bundle = getIntent().getExtras();
String[] imageUrls = bundle
.getStringArray(Constants.GALLARY_IMAGES_IMAGE_BUNDLE_KEY);
mTotalImages = imageUrls.length;
mPageCounter = bundle.getInt(
Constants.GALLARY_IMAGE_POSITION_BUNDLE_KEY, 0);
Log.d("TAG", "Pre Poistion " + mPageCounter);
if (savedInstanceState != null) {
mPageCounter = savedInstanceState.getInt(STATE_POSITION);
}
options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.photo_default)
.showImageOnFail(R.drawable.ic_error).resetViewBeforeLoading()
.cacheOnDisc().imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.displayer(new FadeInBitmapDisplayer(300)).build();
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(new ImagePagerAdapter(imageUrls));
pager.setCurrentItem(mPageCounter);
mLeftArrow.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// int setCounter = mPageCounter - 1;
// if (setCounter >= 0) {
// }
pager.setCurrentItem(pager.getCurrentItem() - 1);
}
});
mRightArrow.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
pager.setCurrentItem(pager.getCurrentItem() + 1);
/*
* int setCounter = mPageCounter + 1; if (setCounter <
* mTotalImages) { pager.setCurrentItem(mPageCounter + 1); }
*/
}
});
}
#Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt(STATE_POSITION, pager.getCurrentItem());
}
private class ImagePagerAdapter extends PagerAdapter {
private String[] images;
private LayoutInflater inflater;
ImagePagerAdapter(String[] images) {
this.images = images;
inflater = getLayoutInflater();
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
#Override
public void finishUpdate(View container) {
}
#Override
public int getCount() {
return images.length;
}
#Override
public Object instantiateItem(ViewGroup view, int position) {
View imageLayout = inflater.inflate(R.layout.item_pager_image,
view, false);
Log.d("TAG", "Poistion " + position);
final ImageViewTouch imageView = (ImageViewTouch) imageLayout
.findViewById(R.id.image);
final DeactivableViewPager viewPager = new DeactivableViewPager(
ImagePagerActivity.this);
imageView.setOnScaleListener(new OnPageScaleListener() {
#Override
public void onScaleBegin() {
viewPager.deactivate();
}
#Override
public void onScaleEnd(float scale) {
if (scale > 1.0) {
viewPager.deactivate();
} else {
viewPager.activate();
}
}
});
imageView
.setSingleTapListener(new OnImageViewTouchSingleTapListener() {
#Override
public void onSingleTapConfirmed() {
Log.d("TAG", "setSingleTapListener");
sCounter++;
if (sCounter % 2 == 0) {
mRlTopOverlayBar.setVisibility(View.GONE);
mRlBottomOverlayBar.setVisibility(View.GONE);
} else {
mRlTopOverlayBar.setVisibility(View.VISIBLE);
mRlBottomOverlayBar.setVisibility(View.VISIBLE);
mRlBottomOverlayBar.setClickable(false);
mRlTopOverlayBar.setClickable(false);
}
}
});
imageLoader.displayImage(images[position], imageView, options,
new SimpleImageLoadingListener() {
#Override
public void onLoadingStarted(String imageUri, View view) {
// spinner.setVisibility(View.VISIBLE);
}
#Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
String message = null;
switch (failReason.getType()) {
case IO_ERROR:
message = "Input/Output error";
break;
case DECODING_ERROR:
message = "Image can't be decoded";
break;
case NETWORK_DENIED:
message = "Downloads are denied";
break;
case OUT_OF_MEMORY:
message = "Out Of Memory error";
break;
case UNKNOWN:
message = "Unknown error";
break;
}
Toast.makeText(ImagePagerActivity.this, message,
Toast.LENGTH_SHORT).show();
// spinner.setVisibility(View.GONE);
}
#Override
public void onLoadingComplete(String imageUri,
View view, Bitmap loadedImage) {
// spinner.setVisibility(View.GONE);
}
});
((ViewPager) view).addView(imageLayout, 0);
return imageLayout;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view.equals(object);
}
#Override
public void restoreState(Parcelable state, ClassLoader loader) {
}
#Override
public Parcelable saveState() {
return null;
}
#Override
public void startUpdate(View container) {
}
}
}
image :
thanks
A better way is to set the top and bottom frame to be clickable, with:
android:clickable="true"
Doing so will make sure that the view/frame itself will trap all clicking events, and will not pass it through the view behind it. Note this method works for all layout/view/controls, but many controls (such as buttons) already have this function on by default.
android:clickable="true" for top and bottom bar.
or give each FrameLayout an onClickListener.
just add this to each of your framelayout view containers so that absorb the click:
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
By default, some controls have clickable property as true.
But the layout doesn't. For layout, we have to make them explicitly clickable so that it will grab the events of clicks or touches and will not let it pass to background views. This is how we do it:
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
Add these lines to all your layouts, so that it will grab/absorb events and will not let it pass to background views.
#gordon1hd1 answer is correct but for those who are still confused, I am adding my layout which contains a FrameLayout as parent and a LinearLayout and twoImageViews as childs.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scroll_parent"
android:orientation="horizontal" />
<ImageView
android:id="#+id/ivArrowLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:src="#drawable/actionbar_back"
android:layout_gravity="left|center_vertical"
android:background="#3f808080"
android:clickable="true"
/>
<ImageView
android:id="#+id/ivArrowRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="4dp"
android:src="#drawable/actionbar_back"
android:layout_gravity="right|center_vertical"
android:background="#3f808080"
android:rotation="180"
android:clickable="true"
/>
</FrameLayout>
Previously, the Linearlayout was also intercepting touch events when either of ImageViews were pressed. Adding android:clickable="true" to both ImageViews resolved the issue.
If you are also facing this type of issue, add android:clickable="true" to the view you want to trap the clicking event.
Simply, Set android:clickable="true" in xml to your foreground view.
imageView.setSingleTapListener(new OnImageViewTouchSingleTapListener() {
#Override
public void onSingleTapConfirmed() {
Log.d("TAG", "setSingleTapListener");
sCounter++;
if (sCounter % 2 == 0) {
mRlTopOverlayBar.setVisibility(View.GONE);
mRlBottomOverlayBar.setVisibility(View.GONE);
pager.requestFocus();
} else {
mRlTopOverlayBar.setVisibility(View.VISIBLE);
mRlBottomOverlayBar.setVisibility(View.VISIBLE);
mRlTopOverlayBar.requestFocus();
mRlBottomOverlayBar.requestFocus();
mRlBottomOverlayBar.setClickable(true);
mRlTopOverlayBar.setClickable(true);
}
}
});
Add android:clickable="true" to rl_bottom_overlay and rl_top_overlay. If you donĀ“t set click events to these layouts (nor via XML neither programatically), no events will be triggered on background views.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/llSettings"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="#ff106279"
android:minHeight="25px"
android:minWidth="25px"
android:onClick="click"
android:orientation="vertical"
android:visibility="visible">
<LinearLayout
android:id="#+id/llSettings1"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="#ff000f"
android:clickable="true"
android:minHeight="25px"
android:minWidth="25px"
android:orientation="vertical"
android:visibility="visible">
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:onClick="buttonclick"
android:text="New Button" />
</LinearLayout>
</RelativeLayout>
and
public void click(View v) {
Toast.makeText(this, "((RelativeLayout)v).toString()", Toast.LENGTH_SHORT).show();
}
public void buttonclick(View v) {
Toast.makeText(this, "Button", Toast.LENGTH_SHORT).show();
}
// For removing click event, sometime click=true not work
relBottomConfirm.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
return;
}
});

Categories

Resources