android-view

Different fling (swipe) velocity on different Android devices with same density

懵懂的女人 提交于 2019-12-20 09:36:04
问题 I'm writing my own image viewer that enables users to swipe left\right to see the next\previous image. I want to animate the image change according to the fling velocity. To detect a fling gesture and its velocity, I followed this basic gesture detection and did as the accepted answer suggested: public class SelectFilterActivity extends Activity implements OnClickListener { private static final int SWIPE_MIN_DISTANCE = 120; private static final int SWIPE_MAX_OFF_PATH = 250; private static

sliding one fragment over another in Android

岁酱吖の 提交于 2019-12-20 09:35:49
问题 In android, can we slide a fragment over another? For example, in the following image : There are two fragments. One is red colored, and the other blue colored. If the user presses his finger on the black colored arrow and drags it to the right, the red colored fragment also drags along with it, thereby covering the blue fragment. In the end, the red fragment covers the whole blue fragment. Also, if the user lifts his finger before the red fragment has been dragged onto less than half of the

When are views attached and detached?

与世无争的帅哥 提交于 2019-12-20 09:15:50
问题 This question is not about how to detect if a view is attached or detached. In general, when is a view attached or detached? Is there a lifecycle diagram for this? To clarify, I'm looking for answers to what happens when: Activity sent to background, opaque view placed on top, visibility set to GONE , view inflated, parent detached, etc. This is not an exhaustive list - I just want to understand how attaching and detaching of views works, at a fundamental level. Update with more examples of

Get the coordinates of the center of a view

谁都会走 提交于 2019-12-20 04:53:39
问题 I am trying to get the center coordinates of my custom view (a circle) so that I can draw a line from the those points. The custom view is inside a TableLayout which is itself inside a FrameLayout . However, I am having trouble - this code doesn't get it right. Any advice please? The values given by this method are wrong on all devices. If I change the layout padding/margins etc. then the dots obviously move, but the point given by this method does not change. public float[]

Get the coordinates of the center of a view

元气小坏坏 提交于 2019-12-20 04:53:00
问题 I am trying to get the center coordinates of my custom view (a circle) so that I can draw a line from the those points. The custom view is inside a TableLayout which is itself inside a FrameLayout . However, I am having trouble - this code doesn't get it right. Any advice please? The values given by this method are wrong on all devices. If I change the layout padding/margins etc. then the dots obviously move, but the point given by this method does not change. public float[]

Is there a way to make a TextView use the Spinner style?

自古美人都是妖i 提交于 2019-12-20 04:28:15
问题 I want to have a TextView look like a Spinner. When you click, a dialog with the choices for the TextView appear. No, I don't want to use a Spinner. I want to use a TextView. 回答1: try this style="?android:attr/spinnerStyle" 来源: https://stackoverflow.com/questions/27596611/is-there-a-way-to-make-a-textview-use-the-spinner-style

Android Invalidate() only single view

眉间皱痕 提交于 2019-12-20 02:55:01
问题 I have 2 views on RelativeLayout I need to invoke(call) onDraw only single view when I try view1.invalidate(); it also invoke(call) onDraw (view2 draw) what to do? thanks 回答1: if view1 is overlapping with view2 when you call view1.invalidate(); it will re-draw every View that is overlapping with it .. so it will call view2.onDraw(); and since you are using RelativeLayout view1 and view2 maybe overlapped each other . 回答2: I met the same question. Finally, I found that drawing cache is disabled

Difference between SurfaceView and ImageView

浪子不回头ぞ 提交于 2019-12-20 00:43:07
问题 I would like to know what is the difference between SurfaceView and ImageView and their usage scenarios. Both seem to be the same. Kindly direct me if there are proper links which I had probably missed. 回答1: Some advantages and differences of a surface view: Better rendering mechanism. threads can update the surface's content without using a handler. This helps for better performance in games and too much animation. So if you need to update GUI rapidly or if the rendering takes too much time

How to set a SearchView's input type to numeric

拜拜、爱过 提交于 2019-12-19 13:09:31
问题 I currently have a SearchView in my app's ActionBar (of which I am populating from an XML layout file) and I am trying to force it to only take numeric input. I've tried setting the android:inputType="number" attribute in XML, but it has no effect. Does anyone know the source of this problem? The XML menu resource: <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/search" android:title="@string/menu_search" android:actionViewClass="android.widget

Android: designing the view for a calendar app

隐身守侯 提交于 2019-12-19 11:32:06
问题 I'm writing a calendar application for Android. The calendar needs to a have a day display similar to the default application, or MS outlook: a grid showing a line for each hour, and the appointments shown as rectangles. Here's a similar sample image from Google Images: I downloaded the source code for the calendar app from Google's Android Open Source Project, and saw that they implemented this display as a custom view which simplay uses Canvas.drawRect() to draw the rectangles, and then