layoutparams

Why do we use setLayoutParams?

守給你的承諾、 提交于 2021-02-07 12:44:14
问题 For example, if you want ot change LayoutParams of some view to WRAP_CONTENT for both width and height programmaticaly, it will look somethong like this : final ViewGroup.LayoutParams lp = yourView.getLayoutParams(); lp.height = ViewGroup.LayoutParams.WRAP_CONTENT; lp.width = ViewGroup.LayoutParams.WRAP_CONTENT; As i undestood getLayoutParams returns reference for params, so this code would be enough, but i often see in examples and so on that after this lines, one follows: yourView

Android view's getTop(), getLeft(), getX(), getY(), getWidth(), getHeight() methods

十年热恋 提交于 2021-02-07 05:11:44
问题 I am writing a drag and drop application and got really confused because of some parameters. Please help to figure out. First of all, I read the documentation for the View class and got the following explanations. getX() : The visual x position of this view, in pixels. getY() : The visual y position of this view, in pixels. getWidth() : Return the width of the your view. getHeight() : Return the width of the your view. getTop() : Top position of this view relative to its parent. getLeft() :

Android view's getTop(), getLeft(), getX(), getY(), getWidth(), getHeight() methods

孤者浪人 提交于 2021-02-07 05:09:32
问题 I am writing a drag and drop application and got really confused because of some parameters. Please help to figure out. First of all, I read the documentation for the View class and got the following explanations. getX() : The visual x position of this view, in pixels. getY() : The visual y position of this view, in pixels. getWidth() : Return the width of the your view. getHeight() : Return the width of the your view. getTop() : Top position of this view relative to its parent. getLeft() :

Android view's getTop(), getLeft(), getX(), getY(), getWidth(), getHeight() methods

流过昼夜 提交于 2021-02-07 05:07:40
问题 I am writing a drag and drop application and got really confused because of some parameters. Please help to figure out. First of all, I read the documentation for the View class and got the following explanations. getX() : The visual x position of this view, in pixels. getY() : The visual y position of this view, in pixels. getWidth() : Return the width of the your view. getHeight() : Return the width of the your view. getTop() : Top position of this view relative to its parent. getLeft() :

Android 7 & 8 Only - ClassCastException: LayoutParams cannot be cast to AbsListView$LayoutParams

戏子无情 提交于 2021-01-27 22:46:48
问题 I have a very odd problem that I'm looking into. I didn't write the original code, but I am investigate why its crashing now, all of a sudden. After looking at it, I don't see any reason for the crash. Also, it works perfectly in lower OS levels (e.g., Android 6); however, its consistently crashing when run in Android 7 and 8. It was also very difficult to reproduce at first, because the crash only manifests after the 6th indices... Was originally thinking that it might be some corrupted data

Set Margin on RecyclerView programmatically

天大地大妈咪最大 提交于 2020-06-08 07:12:47
问题 I need to set the top margin on a RecyclerView programmatically, but I get this exception: java.lang.RuntimeException: Unable to resume activity java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.support.v7.widget.RecyclerView$LayoutParams Here is my code: RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams)recyclerView.getLayoutParams(); int marginTopDp = (int)getResources().getDimension(R.dimen.margin); int marginTopPx = (int)

Add layout with parameters programmatically Android

只谈情不闲聊 提交于 2020-01-19 09:52:51
问题 Hello I have a main screen. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment"/> <ImageButton android:id="@+id/imageButton1" android:layout_width="55dp" android

Add layout with parameters programmatically Android

不想你离开。 提交于 2020-01-19 09:51:08
问题 Hello I have a main screen. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <fragment android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.SupportMapFragment"/> <ImageButton android:id="@+id/imageButton1" android:layout_width="55dp" android

Set LayoutParams on parentless LinearLayout

∥☆過路亽.° 提交于 2020-01-04 13:50:12
问题 I creating LinearLayout programatically then I want to attach it to GridView via custom written adapter. I want to set width and height to my newly created LinearLayout. When I try to do so I get following exception: 03-18 15:50:54.648: E/AndroidRuntime(2708): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams 03-18 15:50:54.648: E/AndroidRuntime(2708): at android.widget.GridView.onMeasure(GridView.java:937) 03-18 15:50:54.648: E/AndroidRuntime(2708): at android.view.View

How to disable screen capture in Android fragment?

耗尽温柔 提交于 2019-12-29 07:48:08
问题 Is it possible to disable screen capture from a fragment? I know the below works for an Activity class onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); } But what if I have a fragment which shows up on top of an activity. Can I somehow disable screen capture? I've tried to set the FLAG_SECURE in the onCreate() or onCreateView() method of the fragment, but it doesn't