android-view

Implement view clicks on multiple ViewHolder types in RecycleView adapter

妖精的绣舞 提交于 2020-01-16 18:10:07
问题 I am implementing multiple ViewHolders as suggested in this answer which uses an abstract bind() . My current Adapter and ViewHolder looks likes: // MyAdapter.java {adapter code} public static abstract class MyViewHolder extends RecyclerView.ViewHolder { public MyViewHolder(View itemView) { super(itemView); } protected abstract void bind(MyModel item); } // ViewHolder1.java public class ViewHolder1 extends MyAdapter.MyViewHolder implements View.OnClickListener { TextView textView; public

How do i draw these kinds custom shape?

余生长醉 提交于 2020-01-16 09:07:10
问题 I have the following design and need to make without using png file if possible. I have done this with the help of png file but i am thinking if there is any other way which is performance centric. I have done this design with the help of png file https://pasteboard.co/Is3RtJY.png How do i draw this myself or use some tool to get this done? 回答1: Use the following code to create this custom shape bg_top_corners_round.xml and save it in your drawable: <shape xmlns:android="http://schemas

Paint Xfermode draws black line on android 2.2

无人久伴 提交于 2020-01-16 00:46:15
问题 I am trying to erase some part of Image, so I am Creating a custom ImageView , so for erasing, I am using following paint to draw mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(Color.TRANSPARENT); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(30); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); I am setting XferMode to PorterDuff.Mode.CLEAR to

What is the difference between LinearLayout and FitWindowsLinearLayout?

老子叫甜甜 提交于 2020-01-15 03:43:10
问题 While creating a Layout, I cam across FitWindowsLinearLayout but can't seem to understand the difference between LinearLayout and FitWindowsLinearLayout . So, when should we use FitWindowsLinearLayout ? FitWindowsLinearLayout 回答1: First, as you can see it is annotated with @hide, which means, that it is not exposed to public API. That means that you should not use it. Secondly, to answer your question: as you can see from the implementation, it has one public method, which sets a listener:

How to get the window instance from a view?

▼魔方 西西 提交于 2020-01-14 19:22:09
问题 i add a view in the windowManager via mWindowManager.addview() . Now i would like to know if it's possible to get the window instance. their is myView.getWindowID() and myView.getWindowToken() but i can't find a way to retrieve from it the window instance 回答1: If your View has been attached to Activity , you can do like this. View view; // your view if (view.getContext() instanceof Activity) { Window window = ((Activity) view.getContext()).getWindow(); } After API 19, there is a convenient

Life cycle of view android

孤街浪徒 提交于 2020-01-13 16:45:48
问题 I want some view animation to occur after resuming my activity, but I can't succeed to catch the time after all the views loaded and the animation started before all the views loaded (before the animation transition). i tried to use onDraw, onWindowFocusChange, onResume, I discovered that onDraw is the last method on the life cycle of view but I still saw that the animation start before the user see the all the views 回答1: Here is Android Activity lifecycle & Android View lifecycle tested on

Life cycle of view android

痞子三分冷 提交于 2020-01-13 16:44:48
问题 I want some view animation to occur after resuming my activity, but I can't succeed to catch the time after all the views loaded and the animation started before all the views loaded (before the animation transition). i tried to use onDraw, onWindowFocusChange, onResume, I discovered that onDraw is the last method on the life cycle of view but I still saw that the animation start before the user see the all the views 回答1: Here is Android Activity lifecycle & Android View lifecycle tested on

Butterknife custom view unbind

[亡魂溺海] 提交于 2020-01-13 08:07:35
问题 What's the best practice for calling : - Butterknife.unbind() in a custom Android view please? 回答1: Yes, onDetachedFromWindow is the right function as mentioned in NJ's answer because this is where view no longer has a surface for drawing. But the usage is incorrectly mentioned in the answer. The right approach involves binding in onFinishInflate() : @Override protected void onFinishInflate() { super.onFinishInflate(); unbinder = ButterKnife.bind(this); } and unbinding in onDetachedFromWindow

Butterknife custom view unbind

时光怂恿深爱的人放手 提交于 2020-01-13 08:07:10
问题 What's the best practice for calling : - Butterknife.unbind() in a custom Android view please? 回答1: Yes, onDetachedFromWindow is the right function as mentioned in NJ's answer because this is where view no longer has a surface for drawing. But the usage is incorrectly mentioned in the answer. The right approach involves binding in onFinishInflate() : @Override protected void onFinishInflate() { super.onFinishInflate(); unbinder = ButterKnife.bind(this); } and unbinding in onDetachedFromWindow

Possible to jump straight to second view in ViewAnimator

三世轮回 提交于 2020-01-13 07:48:07
问题 I have a ViewAnimator ( ViewSwitcher to be precise) with fade in/out animations associated to it and two Views which I transition between using the ViewAnimator.showNext() and ViewAnimator.showPrevious() methods. There is a requirement in my app where sometimes I need to start straight from the second View , without showing a fade animation in going from the first View to the second. Anyone know if there is a straightforward way to accomplish this without having to mess around with the in/out