relativelayout

Android, add view with height in percentage

可紊 提交于 2019-12-11 05:42:06
问题 i wanna add a view with a 100% width and X%(e.g: lets make it 40%) to the parent view i have this: private RelativeLayout getParentView(){ return (RelativeLayout) MyActivity.this.getWindow().getDecorView().getRootView(); } i should cast parent view to LinearLayout or RelativeLayout can achieve this ? and how to set 'myView' width and height in percentage programmatically ? Thanks 回答1: You can do this by simply getting the screen width public static int getScreenWidth(Context context) {

NullPointerException when draw background RelativeLayout

帅比萌擦擦* 提交于 2019-12-11 04:45:47
问题 A silly mistake like this going me crazy, just want to paint the background of a layout of two colors for each view, but I get a nullPointerException. XML FILE: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout android:id="@+id/background_areas" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> .... JAVA FILE: for (int o = 0

Regarding understanding the layout units

雨燕双飞 提交于 2019-12-11 04:27:52
问题 I am calculating the height of some items in a ListView and then I assign the calculated height to the ListView programmatically to ensure that the ListView will expand to accommodate its contents. I calculated the height of the items in the ListView as shown below in the code. As shown in the code, the following line returns a value equal to 533: height += listView.getDividerHeight() * listView.getCount();// The problem I have is, when the height of the ListView is set to the value returned

Layout positioning problem with Custom SlidingDrawer

大兔子大兔子 提交于 2019-12-11 03:42:32
问题 Hi everyone i've been trying to make this work for quite a while and i feel stuck, i found a component on web wich is pretty nice, it allows me top to bottom sliding, the default sample is pretty easy the bar goes on top and the goes down: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/button_open"

Help with Android LinearLayout or RelativeLayout

北战南征 提交于 2019-12-11 01:53:29
问题 I need to create two views programmatically (because I need to access the ondraw of one of the views). For some reason, no matter what I do to add the views to the contentview, they don't show up vertically stacked, one below the other. I can do it just fine using the XML using a RelativeLayout and layout positioning, but with the XML I can't create a view object and overload the ondraw method. What am I doing wrong with the programmatic approach, and how do I solve this problem? LinearLayout

Android - getHeight() and getWidth()

六眼飞鱼酱① 提交于 2019-12-11 00:16:59
问题 I am dynamically creating some ImageViews inside a relativeLayout but I need the size to vary depending on the height and width of the screen. At the point where I set the height the views and layouts havent been created which means that the getHeight() and getWidth() are returning 0. I have looked at other threads on StackOverflow but none seem specific enough to my problem. I am doing all this in a Fragment and would appreciate any guidance on how to solve this. Her is a small snippet of my

In Android, what Layout is faster 1. FrameLayouts inside LinearLayout or 2. One big RelativeLayout?

走远了吗. 提交于 2019-12-10 21:15:18
问题 I am considering two different layout arrangements for a view (which will be a row in a RecyclerView). They are different, but they will both work, either as One container vertical LinearLayout containing rows of FrameLayouts e.g. LinearLayout -> FrameLayouts -> Content One big RelativeLayout that contains all other views (no FrameLayouts but all TextViews, Buttons and such) e.g. RelativeLayout -> Content Now I was wondering: which one would be more preferable in terms of Layout performance?

Android: After drop, editText that was being dragged disapears

£可爱£侵袭症+ 提交于 2019-12-10 20:13:02
问题 I'm trying to create a form in which the user can move inputs around. I have an editText and want it to be able to move it to a new location in my relativeLayout. I am able to pick it up and move it around, but once I let go, it disappears completely. I've tried pretty much everything. I think the onDrag method may not ever be called because my logs never show up. Also, after a let go of my editText, I get this error message in logcat: Reporting drop result: false Another issue I've been

Why nine-patch image in RelativeLayour hides all inner elements?

半城伤御伤魂 提交于 2019-12-10 19:39:26
问题 When I set 9.PNG image as RelativeLayout 's background, all elements inside it gets shrunken to the middle. Here is the XML and the snapshot. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Just a simple white text which does not show up" android:textColor="#ffffff"

Dynamic relative layout in android

帅比萌擦擦* 提交于 2019-12-10 19:23:14
问题 I am trying to have two images on tp of each other. I can have it work fine with an xml file but I would like to do this dynamically. ctdeasyone is a transparent image. So this works fine.. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:id="@+id/bck1" android:src="@drawable/fish2" android:layout_width="wrap_content" android:layout_height