layoutparams

changing the position of ImageView dynamically in android

ⅰ亾dé卋堺 提交于 2019-12-11 00:13:34
问题 all I need to change the position of a ImageView dynamically and iam using the following code int x=100,y=100; RelativeLayout.LayoutParams mparam = new RelativeLayout.LayoutParams((int)(LayoutParams.FILL_PARENT),(int)(LayoutParams.FILL_PARENT)); mparam.topMargin=x; mparam.leftMargin=y; ball.setLayoutParams(mparam); x+=100; y+=100; but i didnt get any change. Is it possible? and How? 回答1: You can call setPadding on your View. So, in your code (which by the way you should put in a code block!),

how to set padding or margin to linear layout?

隐身守侯 提交于 2019-12-10 05:45:09
问题 I have a linear layout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_menu" android:layout_width="fill_parent" android:layout_height="70px" android:layout_alignParentBottom="true" android:background="@drawable/footer_bar" android:gravity="center" > </LinearLayout> When i set condition if (constant.getscreenresolution() >= 800) { //i want to make it height * 2 } So how to set the layout params ? 回答1: hope this helps you LinearLayout

Using layoutparams in relativeLayout with dp

主宰稳场 提交于 2019-12-09 22:24:09
问题 I m making an app and i want to be able to move a view using its margins dynamically. I tried using this : RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)cover.getLayoutParams(); params.leftMargin= 470; params.topMargin= 20; cover.setLayoutParams(params); (cover is an ImageView) The problem with this code its that it uses px instead of dp. I also tried using DisplayMetrics to convert my px values to dp but failed . Can you help me ? 回答1: You need to set margin according to

Android: change LayoutParams of View added by WindowManager

…衆ロ難τιáo~ 提交于 2019-12-09 14:42:33
问题 I have overlay View managed by WindowManager , just like in this question. Briefly, it looks like this: WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); my_view_layout_params = new WindowManager.LayoutParams( WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, PixelFormat.TRANSLUCENT); wm.addView(my_view, my_view_layout_params); It works, but if i need to change layout params, i need to remove View and add it again, like

Getting all MotionEvents with WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH

点点圈 提交于 2019-12-09 13:26:33
问题 My question refers directly to this question. The answer to that question shows how one can create a ViewGroup , embed it inside a WindowManager , and allow the WindowManager to catch MotionEvent s through onTouchEvent(MotionEvent event) . WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH is the flag that allows this this ViewGroup to receive MotionEvent s. However, according to documentation, this flag ...will not receive the full down/move/up gesture I want to know if there's a work

GridView.LayoutParams to be the same in different screen sizes, is it possible?

穿精又带淫゛_ 提交于 2019-12-08 04:28:21
问题 I made a Grid View with 6 columns and 60 rows. Where I can add, move and erase images. But I'm having trouble to set the distance between columns (I don't want any space between columns). Since it will change deppending on screen size. I set it up for my phone, then tried it at a friends phone and there where like 10dp between columns. Heres the xml for the GridView EDIT: and if I try it in a smaller phone the images where to big to fit the cell. <GridView xmlns:android="http://schemas

custom Toast at screen top

强颜欢笑 提交于 2019-12-07 03:05:45
问题 Please read the question before answering with your standard routine to print a Toast :) I'd like to display a Custom Toast at the top left corner of the screen. I use this code to create the Toast: Toast mFixedToast = new Toast(getApplicationContext()); mFixedToast.setDuration(timeout); mFixedToast.setView(myInflatedLayout); mFixedToast.setGravity(Gravity.TOP|Gravity.FILL_HORIZONTAL, 0, 0); mFixedToast.setMargins(0,0); However, in some devices , for example Samsung Galaxy S4, the toast is

Android: How to make the SearchView take up the entire horizontal space in ActionBar?

妖精的绣舞 提交于 2019-12-06 11:15:51
问题 In the following screenshot, the SearchView widget in the ActionBar does not take up the entire space available. I need it to take up all the horizontal space present in the ActionBar (so it spans the entire screen horizontally). What I tried: Programatically, tried this in the onCreateOptionsMenu : View searchViewView = (View) searchView; searchViewView.getLayoutParams().width=LayoutParams.MATCH_PARENT;` This gives: java.lang.NullPointerException: Attempt to write to field 'int android.view

Making a ListAdapter-recycleable Resizable View

不羁的心 提交于 2019-12-06 03:52:28
问题 I'm working on creating a custom view that will have an expanded and condensed state -- in the condensed state, it will just show a label and an icon, and in the expanded state, it will show a message below that. Here is a screenshot of how it works so far: The View itself retains size values for the condensed and expanded states once measured, so it's simple to animate between the two states, and when using the view in normal practice (e.g. in a LinearLayout ) everything works as intended.

Android navigation bar overlay

巧了我就是萌 提交于 2019-12-06 03:50:12
问题 For my application I have to draw a bitmap on top of the Navigation bar on the bottom of the android screen. I am curious to know if the WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY can be used to overlay the navigation bar? 回答1: Use the WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS should work :) 来源: https://stackoverflow.com/questions/21382283/android-navigation-bar-overlay