android-view

Changing CardView shadow color

心已入冬 提交于 2019-12-18 10:35:23
问题 This question was asked on SO many times, but still I didn't find a good solution for this problem. Why do I need this to do? Well because project me and my team develops has iOS style. What did I try? 9.pathch shadow generator but 9.pathes are essentially pngs and it gives me no flexibility and if I'll use this approach I should edit margins everywhere. Carbon library it supports custom shadows and they get drawn outside of view borders, but there is issue regarding rounded rectangles, when

Possible to detect when a TextView's marquee animation has completed?

陌路散爱 提交于 2019-12-18 07:22:12
问题 If I set a TextView's ellipsize value to "marquee" and the marqueeRepeatLimit value to "1" for example (in order to roll a long text across a TextView once), is there any way to detect when the marquee animation has completed? (Thing is, I have a queue of Strings which is being added to dynamically and I want to pull out and show one of these Strings at a time. A String can be longer than the width of the TextView so I want to roll it across before I show the next one.) Edit: If it's not

OnTouch works, but OnClickListener doesn't?

梦想与她 提交于 2019-12-18 03:04:44
问题 I created a widget/control that I can reuse which I created by extending RelativeLayout . Then, in one of my Activities, I created a bunch of these widgets in a loop. However, I ran into an issue when I wanted to have each widget respond to a click. I found that setting OnTouchListener works: this.setOnTouchListener(new OnTouchListener(){ public boolean onTouch(View arg0, MotionEvent arg1) { //Triggers debug message } }); but OnClickListener doesn't: this.setOnClickListener(new View

Android Bitmap Masking (Xfermode) leaves opaque black background behind

*爱你&永不变心* 提交于 2019-12-18 02:44:06
问题 I have a custom view and in the onDraw() , I am trying to perform bitmap masking. I have a squareBitmap (red color) which fills the whole view, and I have a circleBitmap (blue color) that acts as the mask. I am using the mode: PorterDuff.Mode.DST_IN . The result I am expecting is a RED filled circle. I get that, but I also get a BLACK opaque background. I don't want this opaque background, rather it should be transparent. Figure 1 is the result I got, and Figure 2 is the result that I am

Implement multiple ViewHolder types in RecycleView adapter

筅森魡賤 提交于 2019-12-17 23:06:10
问题 It's maybe a discussion not a question. Normal way to implement multiple types As you know, if we want to implement multiple types in RecyclerView , we should provide multiple CustomViewHolder extending RecyclerView.ViewHolder . For exmpale, class TextViewHolder extends RecyclerView.ViewHolder{ TextView textView; } class ImageViewHolder extends RecyclerView.ViewHolder{ ImageView imageView; } Then we have to override getItemViewType .And in onCreateViewHolder to construct TextViewHolder or

Same-named attributes in attrs.xml for custom view

为君一笑 提交于 2019-12-17 17:27:13
问题 I'm writing a few custom views which share some same-named attributes. In their respective <declare-styleable> section in attrs.xml I'd like to use the same names for attributes: <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="MyView1"> <attr name="myattr1" format="string" /> <attr name="myattr2" format="dimension" /> ... </declare-styleable> <declare-styleable name="MyView2"> <attr name="myattr1" format="string" /> <attr name="myattr2" format="dimension" /> ... <

java.lang.IllegalArgumentException: pointerIndex out of range Exception - dispatchTouchEvent

六月ゝ 毕业季﹏ 提交于 2019-12-17 15:54:19
问题 I have this method in my custom view which extends FrameLayout : @Override public boolean dispatchTouchEvent(MotionEvent ev) { int currentItem = vp.getCurrentItem(); if (inDragPanelZone(currentItem, ev.getX(), ev.getY()) && ev.getAction() == MotionEvent.ACTION_DOWN) { if (!shouldAllowPaging()) { return true; } vp.setPagingEnabled(true); } return super.dispatchTouchEvent(ev); } Once in a while - I'm getting the following Exception: java.lang.IllegalArgumentException: pointerIndex out of range

When it's necessary to execute invalidate() on a View?

廉价感情. 提交于 2019-12-17 10:23:24
问题 My answer to this question was just accepted but I started to wonder when exactly one needs to invalidate() a View and when it is not necessary? After a bit of thinking I came to realization that it should work more or less like this: actual drawing of "everything" occurs after onResume() in "free" time parts of the screen can be redrawn but only those that were invalidated (and everything underneath) Therefore, it would seem, if I change something after onResume() (e.g. as a response to a

Why does calling getWidth() on a View in onResume() return 0?

扶醉桌前 提交于 2019-12-17 07:37:47
问题 Everything I've read says you can't call getWidth() or getHeight() on a View in a constructor, but I'm calling them in onResume() . Shouldn't the screen's layout have been drawn by then? @Override protected void onResume() { super.onResume(); populateData(); } private void populateData() { LinearLayout test = (LinearLayout) findViewById(R.id.myview); double widthpx = test.getWidth(); } 回答1: A view still hasn't been drawn when onResume() is called, so its width and height are 0. You can "catch

java.lang.StackOverFlow error. Suspected too many views?

房东的猫 提交于 2019-12-17 06:47:34
问题 When you get an error like the one below (Android 1.5), is it because there are too many nested ViewGroups, or because the total number of Views is too great? Are there any tricks to get around it while still keeping the same look to your app? java.lang.StackOverflowError at android.text.Styled.measureText(Styled.java:371) at android.text.Layout.measureText(Layout.java:1600) at android.text.Layout.getLineMax(Layout.java:654) at android.text.Layout.draw(Layout.java:310) at android.text