FAQ Database Discussion Community


Handling an EditText that was added programatically

android,android-edittext,android-linearlayout,android-relativelayout
I've been making all of my views dynamically, and now I've come to the point where I want to add an EditText for people to write in. I've been able to accomplish this for the most part, but it doesn't look right. I have a linear layout that I'm adding...

Image button in relative layout android not showing the image

android,user-interface,android-relativelayout
I am unable to see the image of the Image button when the image is in relative layout. If i use a different layout, image is working fine. My layout is as follows: <?xml version="1.0" encoding="utf-8"?> <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" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"...

Issue with UI in android

android,android-linearlayout,android-relativelayout
I am trying to achieve the following screen: Hence I tried the following code in XML: <RelativeLayout android:id="@+id/Numberlayout" android:layout_width="match_parent" android:layout_height="75dp" android:layout_marginLeft="5dp" android:visibility="visible" android:layout_marginRight="5dp" android:layout_marginTop="5dp" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:baselineAligned="false" android:orientation="horizontal" > <LinearLayout...

Surround list view by upper and lower elements

android,xml,android-listview,android-relativelayout
The height of the list view should be the white space in the picture without the height of the elements at the bottom. The list view reaches the bottom at the moment but should not. So basically the list view should be surrounded by the upper elements and the lower...

putExtra on dynamically created views android

android,android-layout,android-relativelayout
I have a list of Strings. I am adding a RelativeLayout dynamically for each of them and adding TextViews dynamically in each of the relativelayouts. Now when I click, I am sending this textview value to the next activity. Below is the code. for(int i = 0; i < Names.size();...

What is the optimal width/height to use with pairs of android:layout_align*?

android,android-relativelayout
Let's say I have: <View android:layout_alignTop="@id/someOtherView" android:layout_alignBottom="@id/someOtherView" /> To avoid errors (RuntimeException if not checking before), I need to specify android:layout_height. What value is preferable? It will be overridden anyway, but there may be some performance issues like those that lead to the preference of 0dip/px for LinearLayout children with...

Align Android Relative Layout Items w/ Dynamic Size Item in Different Linear Layout

android,android-layout,android-linearlayout,android-relativelayout
I haven't been able to find anything out there on aligning a widget from a RelativeLayout to a widget within a horizontal LinearLayout. Aligning from one layout to another is almost not even mentioned on the Internet. I thought my question might be easiest explained with a picture. Please pardon...

Put views on a background VideoView

java,android,videoview,android-relativelayout
I have a problem with a VideoView. I have to use a VideView as background and I need to have some views on this videoView. I use a similar code in my layout: <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=".Login" android:alpha="0.9"> <VideoView android:scrollbars="none" android:clickable="false" android:layout_width="fill_parent" android:layout_height="fill_parent"...

Relative Layout: How to center view in the remaining space to the right of an element?

android,android-layout,android-relativelayout
I am trying to center my 'SKIP' button in the center of the remaining space to the right of the little Android icon. How can I do this in a relative layout? Here's my current XML <RelativeLayout android:layout_width="match_parent" android:layout_height="@dimen/min_touch_target_size" android:layout_alignParentBottom="true" android:background="@android:color/transparent" android:orientation="horizontal" > <ImageView android:src="@drawable/ic_android" android:id="@+id/circle_page_indicator" android:layout_width="wrap_content"...

FrameLayout vs Relative Layout for Image overlays

android,framelayout,android-relativelayout
Is there an advantage to using the FrameLayout over the RelativeLayout for image overlays? Would it make sense to use one over the other if I plan to have the background image static , and the foreground image dragged and scaled by the user?

Getting java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widget.RelativeLayout$LayoutParams

android,android-layout,android-contentprovider,classcastexception,android-relativelayout
Here I need to add textview at runtime. first I took reference of RelativeLayout to get layout params but unfortunately its throwing ClassCastException at RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams)contentLayout.getLayoutParams() I also checked - FrameLayout to RelativeLayout ClassCastException even if there is no FrameLayout used, but it didn't work. Since after replacing...

PaddingTop not working on ImageButton

android-relativelayout,android-imagebutton
I have a Imagebutton with a icon of a barcode as the background. I am trying to put a paddingtop on the item so its not touching the top of the screen. The paddingtop works for the textview but not the imagebutton? Any tricks I can try to move it...

Dynamically create textview in center

android,android-layout,android-textview,android-relativelayout
I have a list of items and a relative layout. I want to add as many relative layouts as the no of items in list and textview in each on them. My problem is, I am not able to position the textview in the centre of the layout. Below in...

RelativeLayout on click

android,android-layout,android-relativelayout
I have added RelativeLayouts dynamically to my activity. The number of RelativeLayouts is equal to the number of items in my list.. below is the code: RelativeLayout rt; for(int i = 0; i < Names.size(); i++) { rt=new RelativeLayout(this); } Now if I have 7 items in list hence 7...

RelativeLayout is returning LinearLayout LayoutParams

android,android-linearlayout,android-relativelayout
Here is a snippet from my layout xml that defines my RelativeLayout. <RelativeLayout android:id="@+id/npvirrButtons" android:layout_width="match_parent" android:layout_height="0dp" > <Button android:id="@+id/buttonNPVLabel" android:layout_marginLeft="20dp" android:layout_alignParentLeft="true" android:layout_width="wrap_content" android:layout_height="match_parent" /> <Button android:id="@+id/buttonIRR_NFV" android:layout_marginLeft="20dp" android:layout_marginRight="20dp"...

RelativeLayout doesn't fit in all screen sizes android

android,relativelayout,android-relativelayout
I am developing my first application in android and i am stuck with my xml layout. I have 5 buttons placed vertically in my layout under relativelayout. I am using sony xperia M and according to my screen size the layout looks perfectly fine but for big screens the layout...

How to make RelativeLayout to scroll when in Portrait orientation mode

android,android-layout,scrollview,android-relativelayout
I have these 2 images for Land and Portrait mode orientation (Image 1 for Landscape mode, Image 2 for portrait mode, when I write when in Landscape mode and turn the orientation to portrait it does show the full writing i made in Landscape, therefore I want to make it...

Combining Android RelativeLayout with Gone Views

android,android-layout,optimization,android-relativelayout
Is there a good way to combine RelativeLayout with Views that might be gone? For example if I wanna have a row with four buttons, and the two in the middle might become visibility="gone" during some runtime cases. I can't use android:layout_below because then they will not be neatly arranged...

error after add relativelayout inside linearlayout?

android,android-layout,android-relativelayout
I want to display the video thumbnails in listview, I use images instead of thumbnails and add ImageView (image play button) on the front but failed my xml code like this <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/txttgl" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="5dip"...

Android making bottom tool bar not move to top of layout

android,android-layout,android-relativelayout
This is sort of a continuation of , where I wanted to get a warning text at the bottom of my screen (below my bottom tool bar) when off line. When in offline mode looks correct: However when I hide the offline mode it pops to the top of the...

set layout_below of RelativeLayout within a Relative Layout programmatically

android,android-relativelayout
I have a RelativeLayout @+id/main_layout. Inside the @+id/main_layout, I have a TextView @+id/txt1 and a RelativeLayout @+id/store. For some reason I have to set android:layout_below="@+id/txt1" to the inner RelativeLayout @+id/store programmatically. How to do that?

Removing RelativeLayout.END_OF which is added programmatically

android,android-layout,android-relativelayout
I'm trying to remove RelativeLayout.END_OF from a view's layout parameters which is added programmatically, but it seems that just writing viewLayoutParams.removeRule(RelativeLayout.END_OF) doesn't work and I don't know why! I'm trying to make a live preview based on options and here they are my codes. XML: <RelativeLayout android:id="@+id/liveExample" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/liveExampleLabel">...

RelativeLayout issue doesn't fit in all screen sizes

android,android-relativelayout
I am developing my first application in android and i am stuck with my xml layout. I have 4 textviews in my layout and 2 imagebuttons below the textview. Textview's need to be placed one below the other which differs in size i.e the 1st and 2nd textview is of...

How to add many buttons dynamically giving a line jump before arriving at the edge in Android?

android,android-button,android-relativelayout
I am trying to add many button into Relativelayout or Linearlayout, Layout <Relativelayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" > </Relativelayout> then in the class _ll_layout = (RelativeLayout) findViewById(R.id.container); I only know how add the button dynamically with code. JSONArray jsonArray = new JSONArray(tmp.getString("productos")); Button bt[] = new Button[jsonArray.length()]; // size of...

Detecting first button in layout

java,android,android-layout,android-studio,android-relativelayout
I am trying to solve this conundrum: "How to get rest of the buttons in a list go under the first button." In order to solve that issue, I have tried to set a boolean to detect the first button and apply the rule on anything below that, but button1...

Adding a background image to RelativeLayout hide all others elements

android,background,android-edittext,android-linearlayout,android-relativelayout
I have a simple XML: <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=".LoginActivity" android:background="@drawable/login_background"> <LinearLayout android:orientation="vertical" android:layout_width="320dp" android:layout_height="160dp" android:layout_alignParentBottom="true" android:layout_marginStart="218dp"...

Create RelativeView inside CardView programmatically android studio

java,android,android-relativelayout,android-cardview
I am trying to create a history activity page for my app. I get data from an sql table with the users data, and set that to a card. I have created the first card in my History activity, and I do not want to pre-create all the cards, but...

How to make image distributed to screen width in RelativeLayout?

android,android-layout,relativelayout,android-relativelayout
I have three icon the a RelativeLayout, how to make them distributed to screen width? Since I may add more icon to this line programmatically, I cannot hard code a fixed margin to these icon. <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:layout_width="50dp" android:layout_height="50dp" android:id="@+id/icon1" android:src="@mipmap/icon" /> <ImageView android:layout_width="50dp" android:layout_height="50dp" android:id="@+id/icon2" android:layout_toRightOf="@id/icon1"...

Trying to add a RelativeLayout programmatically but seems like it's off screen or too big

android,android-layout,android-relativelayout
I have this xml for a screen where I at the top I will have a spinner with a list of search conditions, a button next to it (this is what I call control area) and each time is pressed, a group of views will be added for an extra...

Unable to set relativelayout to invisible when activity starts gives NullPointerException

android,android-relativelayout,android-switch
I have a layout where i have a switch and RelativeLayout which contains 2 Image buttons. By default switch remains in the off state. What i want is when the activity loads i want to set the relative layout to b invisible and if the switch is set in the...

Android border bottom for custom view not working

android,android-layout,android-relativelayout
What I'm trying to do is to have a relativelayout with a gradient on it and a gray bottom border, I'm using the below custom view in my application: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/list_item_container" android:layout_width="match_parent" android:layout_height="wrap_content" > <ImageView android:id="@+id/list_item_image" android:layout_width="match_parent" android:layout_height="@dimen/SIZE_LIST_ITEM_LARGE"...

How to design this layout using Relative or Linear layout?

android,android-layout,android-linearlayout,android-relativelayout
Hi I am creating weather widget application. I have completed programming part. I am not familiar with layout design. please help me how to design this layout. Thanks in advance.

Overlapping in RelativeLayout

android,android-layout,android-linearlayout,android-relativelayout
I have one RelativeLayout which contains 2 linearlayouts, one should always be aligned with bottom (for log out purpose.) and the other starts from top and contains 2 viewstubs. These two viewstubs have different heights any only one of them will be visible at same time. My problem is if...

how to add to layout dynamically with multiple RelativeLayout.LayoutParams

android,listview,relativelayout,android-relativelayout
In my fragment, I want each custom item in my listview to look as follows: Name SetsXReps [][][][][] ---> array of textviews [][][][][] ---> array of checkboxes The number of textviews and checkboxes depends upon the item in the adapter, so I need to create that part dynamically. I am...

Android buttons in relative view - Have buttons fill available width

android,layout,android-relativelayout
I have a 9 buttons labeled 1 through 9 in a 3 by 3 Calculator like configuration. These are all contained in a relative view. I would like to have the buttons grow wider than they need to be and fill the available width of the relative view. The relative...

Position ImageViews with an offset programmatically

android,android-relativelayout
I have to create a stack of images programmatically (because they have to be dynamic). I want to stack ImageViews like this: I've tried this, but the images all land up on top of each other: for(int i=0; i<limit; i++){ dynamicButtons[i] = new ImageView(contextSosFragment); int offsetLeft = 15 * i;...

How to put a button in between a sticky 'header' and a Listview in Android

android,android-layout,android-listview,android-button,android-relativelayout
My goal is to have a sticky header, a clear button, and then a ListView (in that order). +-----------------+ | Header | (Sticky) +-----------------+ | "Clear" button | (NOT sticky) +-----------------+ | ListView | (Also NOT sticky) | | | | | | | | | | | | +-----------------+...