android-framelayout

Place view inside FrameLayout in Android

霸气de小男生 提交于 2019-11-30 14:03:01
问题 I want to add a view inside a FrameLayout programmatically and to place it in a specific point within the layout with a specific width and height. Does FrameLayout support this? If not, should I use an intermediate ViewGroup to achieve this? int x; // Can be negative? int y; // Can be negative? int width; int height; View v = new View(context); // v.setLayoutParams(?); // What do I put here? frameLayout.addView(v); My initial idea was to add an AbsoluteLayout to the FrameLayout and place the

ClassCastException LinearLayout LayoutParams

被刻印的时光 ゝ 提交于 2019-11-30 12:50:44
I got an Actionbar and some Fragments. The Problem is my Homescreen. There is an overview Fragment on the left side and a detail Fragment on the right side. My TabListener is Dynamic so i want to set the weight of my Layout programatically. Whenever i try to get the Layoutparams of my LinearLayout i get a ClassCastException: 12-22 16:00:37.620: W/System.err(7235): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams 12-22 16:00:37.625: W/System.err(7235): at com.coover.eu.lostandfound.ListSearchFragment.onViewCreated

Place view inside FrameLayout in Android

限于喜欢 提交于 2019-11-30 09:12:33
I want to add a view inside a FrameLayout programmatically and to place it in a specific point within the layout with a specific width and height. Does FrameLayout support this? If not, should I use an intermediate ViewGroup to achieve this? int x; // Can be negative? int y; // Can be negative? int width; int height; View v = new View(context); // v.setLayoutParams(?); // What do I put here? frameLayout.addView(v); My initial idea was to add an AbsoluteLayout to the FrameLayout and place the view inside the AbsoluteLayout. Unfortunately I just found out that AbsoluteLayout is deprecated. Any

FrameLayout to RelativeLayout ClassCastException even if there is no FrameLayout used

此生再无相见时 提交于 2019-11-30 00:47:41
问题 In my application, I have a layout which has a RelativeLayout to which I want to set margins at runtime programmatically. But when I do that, it gives me ClassCastException saying FrameLayout can not cast to RelativeLayout . I don't have any FrameLayout used, also there are no imports for FrameLayout . Still the problem persists. The xml I am using is: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rl_root"

FrameLayout vs RelativeLayout for overlays

故事扮演 提交于 2019-11-29 22:47:12
I need to implement an overlay (translucent) screen for my app, something similar to Showcase View My guess was to use FrameLayout for this usecase, because it is used to stack items on top of each other. But I was surprised to see that the above library uses RelativeLayout . My question is when to use FrameLayout then, if not in cases like this? What are the disadvantages if I go the FrameLayout way? A common rule of thumb when choosing layouts is to select the combination that results in the smallest number of nested layout views. Specific to your question, RelativeLayout is larger and more

Scale background image to wrap content of layout

北战南征 提交于 2019-11-29 21:22:58
I have a layout that contains some text fields and has a background image that's displayed at the top of my activity. I'd like the background image to scale to wrap the content (don't care about aspect ratio). However, the image is larger than content, so the layout instead wraps the background image. Here's my original code: <RelativeLayout android:layout_width="fill_parent" android:id="@+id/HeaderList" android:layout_gravity="top" android:layout_height="wrap_content" android:background="@drawable/header"> <TextView android:layout_height="wrap_content" android:layout_width="wrap_content"

ClassCastException LinearLayout LayoutParams

最后都变了- 提交于 2019-11-29 18:27:23
问题 I got an Actionbar and some Fragments. The Problem is my Homescreen. There is an overview Fragment on the left side and a detail Fragment on the right side. My TabListener is Dynamic so i want to set the weight of my Layout programatically. Whenever i try to get the Layoutparams of my LinearLayout i get a ClassCastException: 12-22 16:00:37.620: W/System.err(7235): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams

Trying to add a fragment to my fragment container FrameLayout

我怕爱的太早我们不能终老 提交于 2019-11-29 09:05:35
I have created an xml file called editor.xml which contains a FrameLayout. In my main activity I am trying to add my custom fragment to my FrameLayout. The error I receive when trying to add my fragment is: The method add(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, editorFrag) However my editorFrag extends Fragment so I am confused on why this is happening. Below is my code for the files I have mentioned. Any help is appreciated. Editor.xml <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

How to keep an image within layout with drag and drop

耗尽温柔 提交于 2019-11-29 05:21:36
I have the following XML: <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/palette2" android:id="@+id/fl" > <ImageView android:id="@+id/iv" android:layout_width="10dp" android:layout_height="10dp" android:src="@drawable/esquare" /> </FrameLayout> Which gives the following image in my Android Phone How can I code so that user can drag the image anywhere in a layout and the ImageView will always stay within the layout? If X<0 it will be X=(X+imageview.width()) If Y<0 it will be Y=(Y+imageview.height()) If X>layout.width() it will

Android: Set margins in a FrameLayout programmatically- not working

半城伤御伤魂 提交于 2019-11-29 01:44:24
here is the code- FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) searchPin.getLayoutParams(); params.setMargins(135, 176, 0, 0); //params.leftMargin = 135; // also not worked //params.topMargin = 376; searchPin.setLayoutParams(params); Where ever, from xml its working- android:layout_marginLeft="135dp" what can be the reason? am i missing something! -thnx jdo59 Try this: params.gravity = Gravity.TOP; I had a FrameLayout child of a RelativeLayout so the framework was trying to cast FrameLayout params to RelativeLayout, I solved this way FrameLayout mylayout = (FrameLayout) view