How do you design this layout simple? - android

i need to cooperate with IOS developer. He does not know how Android work in layout system. He design a very dynamics UI. Please see my link.
[Link:] http://dl.dropbox.com/u/78582670/layoutdesign.png
Remarks: Orange rectangle mean image buttons.
In this layout, there exist two main views. For View 1, it is a list view. When clicking a item, a View 2 will animate. View 2 move from right to left. Also, it cover the View 1 a bit. After this translation finish, the orange Rect also animate. They move from bottom to the relative position.
I talk to them. If i do that design, the layout cannot be reused. Secondly, i don't want to hard code for playing animation and the UI design.
They think everything is possible and easy to do = =|||.
If you are me, how do you design it?
Here is my solution, but View 2 cannot cover View 1.
public class EducationSystemActivity extends Activity
{
ImageButton mButton1 = null;
ImageButton mButton2 = null;
ImageButton mButton3 = null;
ImageButton mButton4 = null;
ImageButton mButton5 = null;
OnClickListener mImageButtonClickListner = new OnClickListener()
{
#Override
public void onClick(View v)
{
switch(v.getId()){
case R.id.imageButton1:{
Fragment fragment = new TestFragment2();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(R.animator.fragment_slide_left_enter,
R.animator.fragment_slide_left_exit,
R.animator.fragment_slide_right_enter,
R.animator.fragment_slide_right_exit);
ft.replace(R.id.fragment_content, fragment);
ft.addToBackStack(null);
ft.commit();
Toast.makeText(EducationSystemActivity.this, "Button1", Toast.LENGTH_SHORT).show();
break;
}
case R.id.imageButton2:{
Toast.makeText(EducationSystemActivity.this, "Button2", Toast.LENGTH_SHORT).show();
break;
}
case R.id.imageButton3:{
Toast.makeText(EducationSystemActivity.this, "Button3", Toast.LENGTH_SHORT).show();
break;
}
case R.id.imageButton4:{
Toast.makeText(EducationSystemActivity.this, "Button4", Toast.LENGTH_SHORT).show();
break;
}
case R.id.imageButton5:{
Toast.makeText(EducationSystemActivity.this, "Button5", Toast.LENGTH_SHORT).show();
break;
}
}
}
};
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
mButton1 = (ImageButton) findViewById(R.id.imageButton1);
mButton2 = (ImageButton) findViewById(R.id.imageButton2);
mButton3 = (ImageButton) findViewById(R.id.imageButton3);
mButton4 = (ImageButton) findViewById(R.id.imageButton4);
mButton5 = (ImageButton) findViewById(R.id.imageButton5);
mButton1.setOnClickListener(mImageButtonClickListner);
mButton2.setOnClickListener(mImageButtonClickListner);
mButton3.setOnClickListener(mImageButtonClickListner);
mButton4.setOnClickListener(mImageButtonClickListner);
mButton5.setOnClickListener(mImageButtonClickListner);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fragment_content, new TestFragment1());
ft.commit();
}
}
TestFragment2:
public class TestFragment2 extends Fragment
{
LayoutInflater mInflater = null;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d("TestFragment1", "onCreateView");
return inflater.inflate(R.layout.test_fragment2, container, false);
}
#Override
public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
Log.d("TestFragment2", "onCreateAnimator transit:" + transit + " enter:" + enter + " nextAnim:" + nextAnim);
Animator set = null;
if(enter){
set = AnimatorInflater.loadAnimator(this.getActivity(), R.animator.fragment_slide_left_enter);
set.addListener(new AnimatorListener()
{
#Override
public void onAnimationCancel(Animator animation)
{
}
#Override
public void onAnimationEnd(Animator animation)
{
Log.d("TestFragment2", "onAnimationEnd()");
addAnimationSubMenu();
}
#Override
public void onAnimationRepeat(Animator animation)
{
}
#Override
public void onAnimationStart(Animator animation)
{
Log.d("TestFragment2", "onAnimationStart()");
}
});
}
else{
set = AnimatorInflater.loadAnimator(this.getActivity(), R.animator.fragment_slide_left_exit);
}
return set;
}
private void addAnimationSubMenu()
{
ViewGroup submenu_frame = (ViewGroup) getActivity().findViewById(R.id.submenu_frame);
mInflater.inflate(R.layout.fragment1_submenu, submenu_frame, true);
View submenu_layout = getActivity().findViewById(R.id.submenu_layout);
Animation anim = AnimationUtils.loadAnimation(this.getActivity(), R.anim.slide_bottom_to_top);
submenu_layout.startAnimation(anim);
}
}
testfragment2.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFEFE00"
android:padding="0dp"
android:layout_margin="0dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/test2" />
<FrameLayout
android:id="#+id/submenu_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#drawable/menu_drawable">
</FrameLayout>
</LinearLayout>
fragment_submenu1.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/submenu_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/menu_item1"
android:src="#drawable/speech_bubble2x" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/menu_item2"
android:src="#drawable/newspaper2x" />
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/menu_item3"
android:src="#drawable/trolley2x" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/menu_item4"
android:src="#drawable/refresh2x" />
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/menu_item5"
android:src="#drawable/house2x" />
</LinearLayout>

This is Possible you have to use fragments use http://actionbarsherlock.com/ this library will help you to get your requirement and http://xrigau.wordpress.com/2012/03/15/using-an-actionbar-in-your-application-with-actionbarsherlock/ this tutorial will help you to implement the library.

Related

Fragment doesn't respect match parent height when having listview row item has hidden view in it

I am having a weird issue in my app. In one of my app activity I am inflating three fragments in it with tabs. Everything works fine.
In the fragment in which I am having problem, I have listview which is inflated using adapter and data fro web service. This also works well. Now the problem is this the row which is inflated in adapter, has a hidden view which has visibility=gone in xml. On tap of imageview from that row I make that layout visible through java code. The problem is layout doesn't become visible on tap. I have even set breakpoint on the onClickListener of imageview and it does execute the line which changes the visibility from gone to visible. I am unable to understand what is causing this issue as I am using the same row xml with same data in other screen and there it is working perfectly.
UPDATE
I got to know what's causing this issue but don't know how to solve this. In my activity I am having three fragments. The view that I provided for fragment(in which fragment will be inflated) is causing main problem. I have set height width to match parent but it is not taking match parent height. If the fragment just includes normal views like textview, imageview then also fragment is shown properly.But the problem is if fragment consists of listview, then it only takes height of the custom row that is supplied to the listview. I am able to scroll complete listview in that space.
I don't understand what is causing this behaviour.
My Updated code.
Main layout xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<include layout="#layout/header_1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#000"
android:weightSum="3"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:weightSum="1"
android:orientation="horizontal"
android:id="#+id/lin_birds">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="#string/aves"
android:textColor="#ffffff"
android:gravity="center"
android:layout_gravity="center"
android:layout_weight="0.99"
android:id="#+id/fragment_aves"/>
<View
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="0.01"
android:background="#ffffff"
android:layout_marginTop="10dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:weightSum="1"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="#string/routes"
android:textColor="#ffffff"
android:gravity="center"
android:layout_gravity="center"
android:layout_weight="0.99"
android:id="#+id/fragment_routes"/>
<View
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="0.01"
android:background="#ffffff"
android:layout_marginTop="10dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/information"
android:textColor="#ffffff"
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/fragment_information"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/frame_details" />
</LinearLayout>
</LinearLayout>
Main activity java code
public class ActivityRoutesDetails extends AppCompatActivity {
RelativeLayout rel_back;
TextView tv_title,tv_information,tv_routes,fragment_aves;
RoutesDataBean routesDataBean;
LinearLayout frame;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.routes_detail);
tv_title= (TextView)findViewById(R.id.tv_title);
tv_information= (TextView) findViewById(R.id.fragment_information);
tv_routes= (TextView) findViewById(R.id.fragment_routes);
fragment_aves= (TextView) findViewById(R.id.fragment_aves);
// frame= (LinearLayout) findViewById(R.id.frame_details);
routesDataBean= (RoutesDataBean)getIntent().getSerializableExtra("data");
tv_title.setText(routesDataBean.getDescrip1());
Fragment fragment=new FragmentRouteInside();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.frame_details, fragment);
fragmentTransaction.commit();
fragment_aves.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment fragmentBirds=new FragmentRouteBirds();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame_details, fragmentBirds);
fragmentTransaction.commit();
}
});
tv_information.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment fragmentRouteInformation = new FragmentRouteInformation();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame_details, fragmentRouteInformation);
fragmentTransaction.commit();
}
});
tv_routes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Fragment fragment=new FragmentRouteInside();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.frame_details, fragment);
fragmentTransaction.commit();
}
});
rel_back= (RelativeLayout) findViewById(R.id.rel_back);
rel_back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
}
fragment bird 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">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/lv_bird"/>
</LinearLayout>
Fragment java code
public class FragmentRouteBirds extends Fragment {
AppSharedPreferences appSharedPreferences;
String REGISTER_URL="";
ListView lv_birds;
private ArrayList<BirdsDataBean> birdsUrlList;
boolean flag=false;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragments_birds, null);
appSharedPreferences=AppSharedPreferences.getsharedprefInstance(getActivity());
REGISTER_URL = "http://192.241.162.63/appvist/v1/routebird/"+appSharedPreferences.getRouteId();
birdsUrlList = new ArrayList<>();
lv_birds = (ListView) root.findViewById(R.id.lv_bird);
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) lv_birds.getLayoutParams();
lp.height = LinearLayout.LayoutParams.MATCH_PARENT;
lv_birds.setLayoutParams(lp);
hitBirdsService();
return root;
}
private void hitBirdsService() {
class RegisterUser extends AsyncTask<String, Void, String> {
private ProgressDialog mDialog;
RequestClass ruc = new RequestClass();
String response = "";
#Override
protected void onPreExecute() {
super.onPreExecute();
mDialog = new ProgressDialog(getActivity());
mDialog.setMessage("Please Wait ...");
mDialog.setCancelable(false);
mDialog.show();
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
mDialog.dismiss();
parseBirdResponse(response);
//Toast.makeText(getActivity(), s, Toast.LENGTH_LONG).show();
}
#Override
protected String doInBackground(String[] params) {
response = RequestClass.GET(REGISTER_URL);
return response;
}
}
RegisterUser ru = new RegisterUser();
ru.execute();
}
public void parseBirdResponse(String response) {
//String descrip, String observaciones, String descrip_larga, String url_video, String url
try {
JSONObject jsonObject = new JSONObject(response);
Boolean error = jsonObject.getBoolean("error");
if (!error) {
JSONArray jsonArray = jsonObject.getJSONArray("birds");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonBirds = jsonArray.getJSONObject(i);
int idave=jsonBirds.getInt("idave");
String descrip = jsonBirds.getString("descrip");
String observaciones = jsonBirds.getString("observaciones");
String descrip_larga = jsonBirds.getString("descrip_larga");
String url_video = jsonBirds.getString("url_video");
String url = jsonBirds.getString("url");
String nombre_cientifico = jsonBirds.getString("nombre_cientifico");
int flag=jsonBirds.getInt("flag");
birdsUrlList.add(new BirdsDataBean(flag,idave,descrip, observaciones, descrip_larga, url_video, url, nombre_cientifico));
}
ScheduleTaskAdapter scheduleTaskAdapter = new ScheduleTaskAdapter(getActivity(), birdsUrlList);
lv_birds.setAdapter(scheduleTaskAdapter);
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) lv_birds.getLayoutParams();
lp.height = 800;
lv_birds.setLayoutParams(lp);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
public class ScheduleTaskAdapter extends BaseAdapter {
Context context;
LayoutInflater layoutInflater;
// List<InterestAndLanguageBean> interestAndLanguageBeans=new ArrayList<>();
List<BirdsDataBean> imageList = new ArrayList<>();
public ScheduleTaskAdapter(Context context, List<BirdsDataBean> imagesList) {
this.context = context;
this.imageList = imagesList;
layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public int getCount() {
return imageList.size();
}
#Override
public Object getItem(int position) {
return null;
}
#Override
public long getItemId(int position) {
return 0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = layoutInflater.inflate(R.layout.routes_bird_row, parent, false);
holder.iv_birds = (ImageView) convertView.findViewById(R.id.iv_route_bird);
holder.frameLayout = (FrameLayout) convertView.findViewById(R.id.frame_route_bird);
holder.linearLayout = (LinearLayout) convertView.findViewById(R.id.route_bird_detail_view);
holder.imageView = (ImageView) convertView.findViewById(R.id.iv_hide);
holder.iv_video = (ImageView) convertView.findViewById(R.id.iv_seen);
holder.iv_sound = (ImageView) convertView.findViewById(R.id.iv_video);
holder.tv_short_descript = (TextView) convertView.findViewById(R.id.tv_bird_name);
holder.tv_category = (TextView) convertView.findViewById(R.id.tv_scientific_name);
holder.tv_long_description = (TextView) convertView.findViewById(R.id.tv_description);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Uri myUri = Uri.parse(birdsUrlList.get(position).getUrl());
Glide.with(getActivity()).load(myUri).placeholder(R.drawable.birds).into(holder.iv_birds);
holder.tv_short_descript.setText(birdsUrlList.get(position).getDescrip());
holder.tv_long_description.setText(birdsUrlList.get(position).getDescrip_larga());
holder.tv_category.setText(birdsUrlList.get(position).getNombre_cientifico());
final ViewHolder finalHolder = holder;
holder.frameLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finalHolder.linearLayout.setVisibility(View.VISIBLE);
finalHolder.iv_sound.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(birdsUrlList.get(position).getUrl_video())));
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
});
finalHolder.iv_video.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//hitBirdSeenService(birdsUrlList.get(position).getIdave());
// finalHolder.iv_video.setImageResource(R.drawable.eye_selected);
}
});
}
});
holder.imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finalHolder.linearLayout.setVisibility(View.GONE);
}
});
//Picasso.with(context).load(myUri).placeholder(R.drawable.image).into(holder.pic);
//malevich.load(helperTaskBeanList.get(position).getImage()).into(holder.pic);
return convertView;
}
}
static class ViewHolder {
ImageView iv_birds,imageView,iv_video,iv_sound;
FrameLayout frameLayout;
LinearLayout linearLayout;
TextView tv_short_descript,tv_category,tv_long_description;
}
}
And row layout for adapter
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="#+id/frame_route_bird"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:id="#+id/iv_route_bird"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:text="#string/name"
android:textSize="24sp"
android:textStyle="bold"
android:id="#+id/tv_bird_name"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textColor="#ffffff"
android:text="#string/bird_sub_category"
android:id="#+id/tv_scientific_name"/>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="gone"
android:background="#ffffff"
android:id="#+id/route_bird_detail_view"
android:paddingBottom="120dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/bird_hidden_text"
android:textSize="20sp"
android:padding="20dp"
android:id="#+id/tv_description"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/eye110"
android:id="#+id/iv_seen"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/right"
android:layout_marginTop="25dp"
android:layout_marginLeft="15dp"
android:id="#+id/iv_arrow"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/ear"
android:layout_marginLeft="15dp"
android:id="#+id/iv_video"/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="#D6D6D6"
android:layout_marginTop="20dp"
android:src="#drawable/up"
android:layout_gravity="center"
android:id="#+id/iv_hide"/>
</LinearLayout>
</LinearLayout>
Here are the screenshots of the problem
Comparing both images you can see that the hidden view appears in the space of the single row item and is scroll able completely in that space.
Better upshot were targeted at plus for android developers (Cristophe Beils):
"Your ListView must have its height set to match_parent or a fixed size, not wrap_content.
If you need to add another view fixed at the bottom of the ListView as a footer, you need to put both the ListView and the footer View in a vertical LinearLayout and set layout_height to 0dp and layout_weight to 1 on the ListView so that it takes the remaining vertical space."
Try fillViewPort=true on the list view.. But not sure what why yoi have a scroll view inside a list view.. Could be the issue too.
Try setting match_parent as the height of the listview
I suspect this will force the list view to have a defined height and fix your problem.

Create popup window for each gridview item - Android

I'm developing an Android application for a restaurant for an food ordering system.
In my project,I have a Gridview ,When click on a button on the item in gridview, I want to get a popup window with some textfields,buttons etc.
I got help from this document example
the above document example is working alone as single application.it's just an example for creating basic pop-up window.but I need it on Gridview.
my work -->
instead of above doc's main.xml and PopUpWinndowDemoActivity.java (it's main activity),
I use my grid_single.xml and it's implementation file Grid_single.java.
But it doesn't work for me.When I click on the each item's button,not showing the pop-up window as i hope. So, Please help me to solve this or give me a working example for pop-up window on grid view items.
I have attached my files with this.
waiting for your help,
Thank you!
Grid_single.java
Button btnClosePopup;
Button btnCreatePopup;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.grid_single);
btnCreatePopup = (Button) findViewById(R.id.addToCart);
btnCreatePopup.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
initiatePopupWindow();
}
});
btnCreatePopup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
initiatePopupWindow();
}
});
}
private PopupWindow pwindo;
private void initiatePopupWindow() {
try {
// We need to get the instance of the LayoutInflater
LayoutInflater inflater = (LayoutInflater) Grid_Single_Popup.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.screen_popup, (ViewGroup) findViewById(R.id.popup_element));
pwindo = new PopupWindow(layout, 300, 370, true);
pwindo.showAtLocation(layout, Gravity.CENTER, 0, 0);
btnClosePopup = (Button) layout.findViewById(R.id.btn_close_popup);
btnClosePopup.setOnClickListener(cancel_button_click_listener);
} catch (Exception e) {
e.printStackTrace();
}
}
private OnClickListener cancel_button_click_listener = new OnClickListener() {
public void onClick(View v) {
pwindo.dismiss();
}
};
grid_single.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:padding="5dp"
android:id="#+id/grid_single_back"
>
<ImageView
android:id="#+id/grid_image"
android:layout_width="150dp"
android:layout_height="150dp">
</ImageView>
<TextView
android:id="#+id/grid_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textSize="24dp" >
</TextView>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:text="Cutomize & Add"
android:id="#+id/addToCart"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:textSize="18dp"
android:padding="5sp"/>
</LinearLayout>
Thanks in advance
This is working for me, check once
In grid adapter:
public CustomGrid(String[] web, int[] Imageid, Grid_single activity) {
this.Imageid = Imageid;
this.web = web;
this.activity = activity;
}
In getView method of your adapter, keep like this:
grid = inflater.inflate(R.layout.grid_single, null);
TextView textView = (TextView) grid.findViewById(R.id.grid_text);
ImageView imageView = (ImageView) grid.findViewById(R.id.grid_image);
Button btnPopup = (Button) grid.findViewById(R.id.btnPopup);
btnPopup.setOnClickListener(activity);
Grid_single Should implement OnClickListener, and keep like this:
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnPopup:
initiatePopupWindow(web[grid.getPositionForView(v)]);
break;
default:
break;
}
}

view inside tool bar not getting clicked

In my app I'm using a Toolbar. Now in inside my Toolbar I have two ImageViews. When the user clicks on any of the ImageViews I open different Fragment or Activity but in my case I'm not able to click on any of the ImageViews.
*.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:background="#drawable/background"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_home"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#drawable/background"
android:elevation="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/iv_home_about_us"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:src="#drawable/about" />
<ImageView
android:id="#+id/iv_home_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/iv_home_about_us"
android:layout_marginRight="10dp"
android:src="#drawable/search" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<TextView
style="#style/text_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="05dp"
android:gravity="center"
android:text="Trending around me" />
<com.techmorphosis.wheretoday.SlidingTabs.SlidingTabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="10dp" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"></android.support.v4.view.ViewPager>
</LinearLayout>
Complete Code
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.home_screen, container, false);
return view;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle bundle = getArguments();
if (!bundle.isEmpty()) {
position = bundle.getInt(FROM_WHERE_ERROR_OCCURED);
}
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
latitude = SettingPreffrences.getLatitude(contextFrag);
longitude = SettingPreffrences.getLongitude(contextFrag);
if (latitude.equals("") && longitude.equals("")) {
commonFunctions.isLocationAvailable();
commonFunctions.replaceFragment(getActivity(), new ErrorFrag().newInstance(100, 0), false);
} else {
initialize();
}
}
private void initialize() {
toolbar = (Toolbar) view.findViewById(R.id.toolbar_home);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
// actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
// actionBar.setDisplayShowTitleEnabled(false);
ivAboutUs = (ImageView) toolbar.findViewById(R.id.iv_home_about_us);
ivSearch = (ImageView) toolbar.findViewById(R.id.iv_home_search);
pager = (ViewPager) view.findViewById(R.id.pager);
pager.setAdapter(new MyPagerAdapter(getActivity().getSupportFragmentManager()));
tabLayout = (SlidingTabLayout) view.findViewById(R.id.tabs);
tabLayout.setDistributeEvenly(true);
tabLayout.setSelectedIndicatorColors(Color.TRANSPARENT);
tabLayout.setViewPager(pager);
if (position == 0) {
pager.setCurrentItem(0, true);
} else if (position == 1) {
pager.setCurrentItem(1, true);
} else if (position == 2) {
pager.setCurrentItem(2, true);
}
ivAboutUs.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(contextFrag, "Yess", Toast.LENGTH_SHORT).show();
}
});
ivSearch.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.iv_home_about_us:
commonFunctions.replaceFragment(getActivity(), new AboutUsFrag(), false);
break;
case R.id.iv_home_search:
Intent intent = new Intent(contextFrag, SearchScreen.class);
contextFrag.startActivity(intent);
break;
}
}
}
class MyPagerAdapter extends FragmentPagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
#Override
public Fragment getItem(int position) {
Fragment fragment = null;
if (position == 0) {
fragment = new TodayFrag();
}
if (position == 1) {
fragment = new TommorowFrag();
}
if (position == 2) {
fragment = new LaterFrag();
}
return fragment;
}
#Override
public int getCount() {
return 3;
}
}
You can't access the UI element in onCreateView method - EVER
Use onActivityCreated method , that tell the fragment the activity is fully created and ready to interact.
#Override
public void onActivityCreated(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
ImageView ivAboutUs = (ImageView) view.findViewById(R.id.iv_home_about_us);
ivAboutUs .setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
This might be an issue where the touch events never reach the ImageViews because they were absorbed by something else. I ran into something similar where I was trying to put an onClickListener on an Imageview embedded in a list item. No matter how much I clicked on the imageView, something else was eating up the touch events(Most likely the View that makes up the ListView Item. I fixed the problem by changing the ImageView to an ImageButton and setting its background to null (So that the imageButton would look like an imageView and not an image button.) Once I did that, clicking the images worked for me. Try changing your ImageViews to look like this:
<ImageButton
android:id="#+id/iv_home_about_us"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:background="#null"
android:src="#drawable/about" />
<ImageView
android:id="#+id/iv_home_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/iv_home_about_us"
android:layout_marginRight="10dp"
android:background="#null"
android:src="#drawable/search" />
I hope this helps. Good luck.

Click of an ImageView in a list item is not happening properly

I have a ListView, which m using to display the list of questions one at a time. I have used 5 ImageView in a list item i.e. each list item ( question ) has 5 answers.
What I need, is that when I click any of the image then it should first display the black background color of the selected image for say 500 milliseconds and then it should move to next question.
Currently when I click on any list item it's straight away moving to the next question without displaying black background.
que.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lyot"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/iv1"
android:layout_width="75dp"
android:layout_height="78dp"
android:background="#drawable/selector_iv1"
android:clickable="true"
android:src="#drawable/sa" />
<ImageView
android:id="#+id/iv2"
android:layout_width="75dp"
android:layout_height="78dp"
android:src="#drawable/sb" />
<ImageView
android:id="#+id/iv3"
android:layout_width="75dp"
android:layout_height="78dp"
android:src="#drawable/sc" />
<ImageView
android:id="#+id/iv4"
android:layout_width="75dp"
android:layout_height="78dp"
android:src="#drawable/sd" />
<ImageView
android:id="#+id/iv5"
android:layout_width="75dp"
android:layout_height="78dp"
android:src="#drawable/se" />
</LinearLayout>
layout.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="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/queList"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_marginBottom="25dp"
android:divider="#null"
android:focusableInTouchMode="false"
android:overScrollMode="never"
android:scrollbars="none" />
</LinearLayout>
Activity.java
public class Activity extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
ListView queList = (ListView) findViewById(R.id.queList);
refreshQuestionList();
}
private void refreshQuestionList()
{
queList.setAdapter(new quesAnsListAdapter(context));
queList.setSelection(currentQuestionPosition);
}
private class quesAnsListAdapter extends BaseAdapter
{
private Context mContext;
public quesAnsListAdapter(Context context)
{
mContext = context;
}
public int getCount()
{
return 10;
}
public Object getItem(int position)
{
return myArrayListItem;
}
public long getItemId(int position)
{
return position;
}
public View getView(final int position, View convertView, ViewGroup parent)
{
ViewHolder holder = new ViewHolder();
View row = convertView;
if (row == null)
{
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
row = inflater.inflate(R.layout.que, null);
holder.iv1 = (ImageView) row.findViewById(R.id.iv1);
holder.iv2 = (ImageView) row.findViewById(R.id.iv2);
holder.iv3 = (ImageView) row.findViewById(R.id.iv3);
holder.iv4 = (ImageView) row.findViewById(R.id.iv4);
holder.iv5 = (ImageView) row.findViewById(R.id.iv5);
row.setTag(holder);
}
else
{
holder = (ViewHolder) row.getTag();
}
holder.que.setText("Que"+position);
for (int i = 0; i < ansBeanList.size(); i++)
{
final AnsBean ab = ansBeanList.get(i);
switch (i)
{
case 0:
holder.iv1.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
v.setBackgroundColor(Color.BLACK);
smilyClick(position);
}
});
break;
case 1:
holder.iv2.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
v.setBackgroundColor(Color.BLACK);
smilyClick(position);
}
});
break;
case 2:
holder.iv3.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
v.setBackgroundColor(Color.BLACK);
smilyClick(position);
}
});
break;
case 3:
holder.iv4.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
v.setBackgroundColor(Color.BLACK);
smilyClick(position);
}
});
break;
case 4:
holder.iv5.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
v.setBackgroundColor(Color.BLACK);
smilyClick(position);
}
});
break;
default:
break;
}
}
return row;
}
class ViewHolder
{
ImageView iv1, iv2, iv3, iv4, iv5;
}
}
private int currentQuestionPosition=0,finalQuestionPosition=9;
private void smilyClick(int oldQuestionPosition)
{
boolean answerInsertedOrUpdated = false;
if (oldQuestionPosition < finalQuestionPosition)
currentQuestionPosition = (oldQuestionPosition + 1);
if (oldQuestionPosition < finalQuestionPosition)
{
refreshQuestionList();
}
}
}
When you start the app currentQuestionPosition=0,finalQuestionPosition=9;
in smilyClick you do refreshQuestionList() which is called based on the values stated before.
But this method removes the adapter and creates new, and that causes whole ListView to redraw.

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