android-custom-view

TextView: onDraw getting called only once

不羁的心 提交于 2019-12-24 13:47:16
问题 I have a situation where I want to debug calls to TextView.onDraw() so I subclassed it like this: public class MyTextView extends AppCompatTextView { View parent; public MyTextView(Context context) { super(context); } public MyTextView(Context context, AttributeSet attrs) { super(context, attrs); } public MyTextView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public void storeParent(View parent) { this.parent = parent; } @Override protected

Custom EditText - Material Design

若如初见. 提交于 2019-12-24 12:07:57
问题 I developed an own class, which extends EditText. But my custom view has an other look as the normal view. public class DateEditText extends EditText { [...] public DateEditText(Context context, AttributeSet attrs) { super(context, attrs); init(); } public DateEditText(Context context) { super(context); init(); } public DateEditText(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } private void init() { setInputType(InputType.TYPE_CLASS

Rounded view with title and text inside

こ雲淡風輕ζ 提交于 2019-12-24 09:04:33
问题 How can I make this? It looks nice and I'd like to use something like this. The lines at the top should correspond to the end of the title 回答1: Actually, these types of view are mostly done with custom views. This tutorial is useful for custom views. But you can cheat a little bit, create backgound.xml inside the drawable folder, and paste the code: <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <stroke

Custom ListView (with CheckBox) not responding to clicks

旧时模样 提交于 2019-12-24 07:45:39
问题 I've created a custom ListView using my own version of ArrayAdapter. My problem is that it is not responding to any onItemClickListeners. Here are my code snippets: final ArrayAdapter<Agency> aa=new myCustomAdapter(); lv.setAdapter(aa); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View myView, int pos, long id) { TextView clickedTV=(TextView)myView.findViewById(R.id.rowtext1); Toast.makeText(getBaseContext(),

How to invoke drag event of a custom view inside SurfaceView?

↘锁芯ラ 提交于 2019-12-24 06:48:09
问题 How can i drag a custom view inside the SurfaceView. Touch events are not dispatched to child custom view from SurfaceView or child view's onTouchEvent is not called. 回答1: Try this code public class MoveViewTouchListener implements View.OnTouchListener { private GestureDetector mGestureDetector; private View mView; public MoveViewTouchListener(View view) { mGestureDetector = new GestureDetector(view.getContext(), mGestureListener); mView = view; } @Override public boolean onTouch(View v,

How to invoke drag event of a custom view inside SurfaceView?

﹥>﹥吖頭↗ 提交于 2019-12-24 06:47:16
问题 How can i drag a custom view inside the SurfaceView. Touch events are not dispatched to child custom view from SurfaceView or child view's onTouchEvent is not called. 回答1: Try this code public class MoveViewTouchListener implements View.OnTouchListener { private GestureDetector mGestureDetector; private View mView; public MoveViewTouchListener(View view) { mGestureDetector = new GestureDetector(view.getContext(), mGestureListener); mView = view; } @Override public boolean onTouch(View v,

Android build mini navigation drawer with Icons

夙愿已清 提交于 2019-12-24 06:05:23
问题 I want to build a fixed mini nav drawer in android. will will always be visible an not extendable, with icons only. Something like https://github.com/mikepenz/MaterialDrawer Mini Drawer. I try used his library, but I can't figured out how to make it fixed. here is my code: private Drawer result = null; private MiniDrawer miniResult = null; result = new DrawerBuilder() .withActivity(this) .withToolbar(toolbar) .withTranslucentStatusBar(false) .addDrawerItems( new PrimaryDrawerItem().withName(

Android: Only make certain part of custom view be clickable

纵饮孤独 提交于 2019-12-24 06:04:42
问题 I have a custom view, assume it looks like this: I would like for my custom view to respond to the onClicks, however the catch is that I would like it to respond to the clicks ONLY on the red portion/circle. Not the whole view. Is it possible to make to make the text above and the grey portion not clickable? Thank you. 回答1: In a custom view, you handle clicks by overriding the onTouchEvent method of android's View class. First check that the location the user has clicked is within the circle.

Diamond Shaped Button with transparent borders

半城伤御伤魂 提交于 2019-12-24 04:06:44
问题 I used a customView class for create a diamond shape button. In onDraw method of this class: @Override protected void onDraw(Canvas canvas) { mPath.moveTo(mWidth/2 , 0); mPath.lineTo(mWidth , mHigh/2); mPath.lineTo(mWidth /2 , mHigh); mPath.lineTo(0 , mHigh/2); mPath.lineTo( mWidth/2 ,0); canvas.drawPath(mPath ,mBorderPaint); super.onDraw(canvas); } And borderPaint defined like this: mBorderPaint = new Paint(); mBorderPaint.setColor(mBorderColor); mBorderPaint.setStyle(Paint.Style.FILL_AND

How do I “restart” a touch event in Android?

折月煮酒 提交于 2019-12-24 03:03:48
问题 I have a custom View and I'm overriding onTouchEvent(MotionEvent) . I've implemented pinch-zoom in this view as described in the article Making Sense of Multitouch. The issue I'm having is that this view is ultimately used in a Gallery which needs touch events for scrolling. I've added logic to detect when my view has fully scrolled to the right/left and return false, but I think the Gallery needs the full MotionEvent motion in order to scroll. Here's where I return false: case MotionEvent