layoutparams

Creating a button in Java, causes getLayoutParams to return null

北慕城南 提交于 2019-12-25 02:11:13
问题 I need to create a button in Java. Below is my code: Button b = new Button(MyClass.this); b.requestLayout(); LayoutParams lp = b.getLayoutParams(); lp.height = LayoutParams.WRAP_CONTENT; lp.width = LayoutParams.WRAP_CONTENT; b.setLayoutParams(lp); b.setText("bla"); b.setTextSize(16); b.setOnClickListener(myListener); I then add this button to the bottom of a ListView: getListView().addFooterView(b); However this crashes, because getLayoutParams returns null. Even if I create new LayoutParams

Android: RelativeLayout margin works but gets overridden

前提是你 提交于 2019-12-25 01:46:49
问题 Problem Using RelativeLayout.LayoutParams and marginTop before setLayoutParams( params ) . Works on all devices for half a second but some cases it bumps back to top. The view stays centered in the holding view on my Moto X 2014 running Lollipop but not on my Nexus 4 running Lollipop . Opening activity Opens activity The margin is fine and the SurfaceView is centered ~200ms delay The margin resets and its back to top (top of SurfaceView at the top of holder) Closing activity Back pressed

Detect gestures without blocking other apps

好久不见. 提交于 2019-12-24 19:20:47
问题 I want to create system overlay view, which detect gestures without blocking other apps. How can i do it (apps like OmniSwipe, Easy Swipe detect gestures without blocking anything)? Below code, which blocking other apps cause of system overlay view. package com.carxsing.anglelockscreen.GestureDetector; public class GestureService extends Service implements GestureOverlayView.OnGesturePerformedListener{ private WindowManager windowManager; private GestureOverlayView GestureOverlay,

Dynamically add layouts (Relative Layouts) beneath each other in Android

北战南征 提交于 2019-12-24 18:09:06
问题 I am trying to create a method where each time I click a button, I want the screen to display a Relative Layout box below one that is currently there or create one at the top if there isn't one there and I want it to keep creating them below from each button click. Currently using this method, nothing happens when the button is clicked. Here is the code that I have so far and can someone please help me see what I am doing wrong and what I can do to fix this issue: public void createNewLayout(

Dynamically add layouts (Relative Layouts) beneath each other in Android

末鹿安然 提交于 2019-12-24 18:08:02
问题 I am trying to create a method where each time I click a button, I want the screen to display a Relative Layout box below one that is currently there or create one at the top if there isn't one there and I want it to keep creating them below from each button click. Currently using this method, nothing happens when the button is clicked. Here is the code that I have so far and can someone please help me see what I am doing wrong and what I can do to fix this issue: public void createNewLayout(

How Do I Set My View LayoutParams Width Smaller?

拜拜、爱过 提交于 2019-12-24 06:47:46
问题 Hi I am borrowing Seth's method found here to animate my viewGroups. It works great but in the wrong direction - This is my first time using/extending the Animation class and I cant figure how to decrease the size of my view -This expands it. Below is the class and how I use it. Any help will be greatly appreciated. public class ContainerAnim extends Animation { int targetWidth; View view; boolean opened; public ContainerAnim(View v, int targetWidth, boolean opened) { this.view = v; this

Differences between: myView.getLayoutParams().height = screenHeight and myView.setLayoutParams(lp)?

落花浮王杯 提交于 2019-12-24 04:29:46
问题 When it comes to change the height of a layout dynamically, I usually set the desired dimensions using LayoutParams like: RelativeLayout myView = (RelativeLayout) v.findViewById(R.id.myView); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.FILL_PARENT, screenHeight); myView.setLayoutParams(lp); But there is this shorter version as well: myView.getLayoutParams().height = screenHeight; Both are working in my case, I would prefer the second version

Differences between: myView.getLayoutParams().height = screenHeight and myView.setLayoutParams(lp)?

て烟熏妆下的殇ゞ 提交于 2019-12-24 04:29:25
问题 When it comes to change the height of a layout dynamically, I usually set the desired dimensions using LayoutParams like: RelativeLayout myView = (RelativeLayout) v.findViewById(R.id.myView); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.FILL_PARENT, screenHeight); myView.setLayoutParams(lp); But there is this shorter version as well: myView.getLayoutParams().height = screenHeight; Both are working in my case, I would prefer the second version

Add a margin to LinearLayout in Android

笑着哭i 提交于 2019-12-23 12:33:49
问题 I have some problems with setting margin! body_content = (LinearLayout) findViewById(R.id.body_content); int gSLength = 2; body_content.setPadding(10, 0, 10, 0); for (int i = 0; i < 1; i++){ FrameLayout fl = new FrameLayout(this); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, 90); fl.setLayoutParams(params); LinearLayout ll1 = new LinearLayout(this); LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 30); params1.setMargins(0, 60,

How do I get the `layout_weight` of a TextView?

血红的双手。 提交于 2019-12-23 06:02:28
问题 I have a TableLayout and a row with a couple TextViews . I want to find the layout_weight of the TextView but I cant figure out how. I've tried the following: TableRow.LayoutParams lp = tv1.getLayoutParams(); and: ViewGroup.LayoutParams lp = tv1.getLayoutParams(); In the first case I get a type mismatch: "Cannot convert from ViewGroup.LayoutParams to TableRow.LayoutParams", and the second case works fine, however ViewGroup.LayoutParams doesn't have a weight field. All the different types of