android-view

Replacing View with SurfaceView to draw on other than the UI Thread

僤鯓⒐⒋嵵緔 提交于 2019-12-11 03:45:27
问题 The following program does not work unless the line while (!done) (and the closing bracket) are uncommented. Do you understand why? Why is it not possible to ask the thread to run the drawing code just once? public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback { private SurfaceHolder holder; private MyThread myThread; private boolean hasSurface; protected float x, y; protected Paint paint; public MySurfaceView(Context context, AttributeSet attrs) { super(context,

How to force View to recalculate it's position after changing parent

家住魔仙堡 提交于 2019-12-11 03:29:16
问题 It has been some days since I have this problem. This is a reformulation of this question considering the behavior I describe on this answer. Please, note that this question states for a less specific case, and the answer could be useful for many different scenarios. I'm moving one chip from the left point to the right point, and writing original and new coordinates: So this is failing: public void onTouch(View view) { int[] aux = new int[2]; //Get the chip View movingChip = findViewById(R.id

How to scale a view in android using a handle?

有些话、适合烂在心里 提交于 2019-12-11 03:14:42
问题 I'm trying to implement a handle to scale a view in android. Instead of using something like multitouch I want to be able to resize an image with just one finger. Here is my activity code. I feel as though I am very close there are a five things that don't work properly. The scaling is off. It grows at a much faster rate than it should. Solved Thanks @Salauyou The view will only grow, and not shrink. Solved Thanks @Salauyou The handle view doesn't move with the image. Solved Thanks @Salauyou

How do I manipulate a View from another class in Android?

微笑、不失礼 提交于 2019-12-11 01:37:45
问题 I have a handler for receiving SMS in a seperate class. How can I make it change the view elements when the handler is executed? Here is my code: public class MainActivity extends MapActivity { MapView mapView; MapController mc; GeoPoint p; private int carNumber; private String langt; private String longt; CheckedTextView text; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R

Android - add subview with layout params at specific index (in code)

六眼飞鱼酱① 提交于 2019-12-11 01:36:38
问题 I may be missing something, but I can't find a way to add a subview to a view at a specified index with specific layout params. There's addView(View v, LayoutParams lp) and there's addView(View v, int index) - but I can't find a way to specify both. What am I missing? 回答1: Why, there's a method with both: addView(View child, int index, ViewGroup.LayoutParams params) : Here. 回答2: Here is an example. I use it to show a progress indicator on any view. final ViewGroup rootFrameLayout = (ViewGroup

Continues Runtime Exception : android.view.DisplayListCanvas.throwIfCannotDraw on samsung devices

半城伤御伤魂 提交于 2019-12-11 01:25:59
问题 I am having multiple crashes on play store console, I have checked all images in the drawable folder and it seems to be fine to me as I suspect this can cause the issue. It is mostly crashing on samsung devices as per report. Please suggest what wrong is happening. Also for background images I am using this size: hdpi :480*800 xhdpi: 640*960 xxhdpi 1440*2560 xxxhdpi: 1440*2560 `at android.view.DisplayListCanvas.throwIfCannotDraw (DisplayListCanvas.java:260) at android.graphics.Canvas

Set child's style from the Viewgroup in Android?

帅比萌擦擦* 提交于 2019-12-11 01:18:21
问题 Say I want to set all the EditText fields in my Linear Layout to be single-line, how should I achieve that? Detailed Code: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" style="@style/LoginTextFieldTheme" > <EditText android:id="@+id/textPassword" android:layout_weight="1" android:layout_width="0dp" android:inputType="textPassword" android:hint="password" /> <EditText android:id="@+id/textPasswordConfirm" android:layout

ViewPager and setClipChildren(false) workaround for 2.x devices

邮差的信 提交于 2019-12-11 01:04:22
问题 I am using Dave Smith's solution to make ViewPager behave like an image gallery. My problem is that setClipChildren(false) does not work on devices with 2.x (tried on HTC Desire S and Samsung Galaxy S, both with 2.3.5). Only one image is shown, and scrolling is only inside the viewpager area. Searching, I have found two solutions: setClipChildren(false); setLayerType(View.LAYER_TYPE_SOFTWARE, null); set to the container of the ViewPager, and on the pager, but setLayerType works only on API 11

Use 2 (or more) colors for a button text

*爱你&永不变心* 提交于 2019-12-11 00:01:32
问题 I know I can change the color of the text on a button by the following ways : button.setTextColor(getApplication().getResources().getColor(R.color.red)); //TAKE DEFAULT COLOR or button.setTextColor(0xff0000); //SET CUSTOM COLOR or button.setTextColor(Color.parseColor("#ff0000")); However I want to use two colors for the text : for example, suppose my button has the following text : "Click Here" , I want the "Click" part to appear in red, and the "Here" part in blue. Is this possible ? 回答1:

Difference between setAdapter() and setDropDownViewResource() on Spinner

心已入冬 提交于 2019-12-10 22:22:43
问题 I looked at this question Difference between android.R.layout.simple_spinner_dropdown_item and android.R.layout.simple_spinner_item, but couldn't find an answer to my question. I can see that there is a difference between simple_spinner_item and simple_spinner_dropdown_item. But why do I need to set them both? Which part of Spinner layout is controlled by layout set in setAdapter() (simple_spinner_item ) and which one by layout set in setDropDownViewResource() (simple_spinner_dropdown_item) ?