FAQ Database Discussion Community


Customize the spinner in Android is giving space issue

android,spinner,relativelayout,android-spinner
I have customize the background of the spinner. I have removed the background and showing a spinner down arrow beside that. But if the text are not properly aligned. The bigger length text is showing in complete area but for smaller text, there is a gap coming for text and...

How to add relative Layout below some element dinamically

java,android,xml,parameters,relativelayout
Please help me to add a RelativeLayout below a RadioButton dynamically (I have to create RelativeLayout and RadioButton in class). Something like this: <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <RadioButton android:id="@+id/radioButton3" android:text="RadioButton" /> <RelativeLayout android:id="@+id/relativeLayout2" android:layout_below="@+id/radioButton3" android:layout_width="match_parent" android:layout_height="wrap_content"> </RelativeLayout>...

Creating a layout Multiple times in android

android,android-layout,relativelayout,layoutparams
How to create a whole layout (Relative/Linear) multiple times in android.I want the same layout to be created multiple times inside a horizontal scroll view. If anyone knows the answer Please help me ASAP as I am working on it for a long time.

Android. Fix the height of a fragment on all screens

android,fragment,android-linearlayout,relativelayout
I have this xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/infoinstalacion_fragment1_relative_imagen_poli" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/Pink"> <ImageView android:id="@+id/infoinstalacion_fragment1_imgfoto" android:layout_width="match_parent" android:layout_height="wrap_content" android:scaleType="fitXY" android:src="@drawable/pol_alza" />...

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...

how to align controls left, right and center in relative layout in android

android,android-layout,relativelayout
I have 3 controls which I want one aligned left, the other centered, and the last all the way to the right in a relative layout. I have tried that with the following: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="match_parent"> <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android">...

First time programmer confused as to why the EditText and Button fields aren't going where I want them to

android,xml,textview,android-linearlayout,relativelayout
I am coding in XML on android studios, and I am having trouble getting the EditText to be centered at the top and the Button to be centered in the center. I do not know a lot about code so the other things I've read about Relative vs Linear Layout...

Overlapping counter textview on image in relativelayout or linearlayout

android,android-linearlayout,relativelayout
I want to place a textview on top right corner of imageview and also to overlap some part of textview on to imageview. How can i do that. Right now I am doing this: <RelativeLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_marginLeft="12dip" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imgMessage" android:src="@drawable/listing_message" /> <TextView android:id="@+id/tvMessageCounter" android:layout_width="20dip"...

How I set the width of RelativeLayout to screen width?

android,width,screen,relativelayout,resolution
I have this RelativeLayout component and I want to set it to the entire screen width. How can I do that? atendente.xml <?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content"> <RelativeLayout style="@style/layoutAtendenteBalao" android:id="@+atendente/rltAtendenteBalao"> styles.xml <style name="layoutAtendenteBalao"> <item name="android:layout_width">fill_parent</item>...

ImageView background with height match_parent doesn't work

android,android-layout,imageview,relativelayout
There's something that is not working well here. What I need: fill a part of a RelativeLayout with an ImageView with a pattern background. What I have done: If i put defined number (in DP) to the ImageView height, it works. But it's not what I need, because the RelativeLayout...

Programmatically RelativeLayout.ALIGN_RIGHT with a given View.getId() not working

java,android,relativelayout
i try to align a TextView programmatically to the right/bottom edge of a button. However, this static xml code is working: <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Text" android:id="@+id/textView10"...

How to change focus after scaling view?

android,focus,scale,relativelayout
To scale view I use next code: relativeLayout.setScaleX(scale); relativeLayout.setScaleY(scale); But after it I have the next:1 So it is offset. I need to make it not offset. I need to add some thing like pivot point for canvas but it must be for view....

Relative layout gradient mask android

android,xml,relativelayout
Hi i'm now developing application that contain a profile like twitter profile I got a small problem . the problem is how to make a gradient black trasparent mask effect like this can anyone help me or provide me a code how to make this effect with xml please thank's...

Xamarin Forms Relative Layout won't stack

c#,xaml,xamarin,relativelayout,xamarin.forms
With the following code: <ScrollView Orientation="Vertical" Padding="0"> <RelativeLayout BackgroundColor="Red" Padding="0"> <BoxView Color="Blue" WidthRequest="100" HeightRequest="100" RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=0}" RelativeLayout.YConstraint="{ConstraintExpression Type=Constant, Constant=0}" /> </RelativeLayout> <RelativeLayout BackgroundColor="Green" Padding="0"> <BoxView Color="Yellow" WidthRequest="100" HeightRequest="100"...

Android, RelativeLayout in Adapter is causing ERROR

android,android-listview,android-linearlayout,relativelayout
I am trying to make a chat bubble, I have successfully did it with a text only, but when i want to add another text to put the time inside the bubble i had to add a RelativeLayout to put it on the actual linear layout, but this time i...

Is layout_above broken? this simple layout is driving me crazy

android,android-layout,relativelayout
here is my code <TextView android:id="@+id/BIG" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="BIG" android:textSize="50dp" /> <TextView android:id="@+id/small" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@id/BIG" android:layout_toRightOf="@id/BIG" android:text="small" android:textSize="10dp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"...

Android: adding programmatically a TextView is not working

android,textview,relativelayout
I have an issue while trying to add a TextView to a RelativeLayout. My code is this one: TextView lectureView = new TextView(this); LayoutParams lp=new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); //lp.setMargins(0,60,0,0); lectureView.setTextColor(0xffffff); lectureView.setBackgroundColor(0x000080); lectureView.setText(lect.getCourse().getName()); ((RelativeLayout)findViewById(R.id.mondayRelativeLayout)).addView(lectureView); ((RelativeLayout)findViewById(R.id.mondayRelativeLayout)).invalidate(); But...

scroll bar doesn't scroll to the last view

android,scrollview,relativelayout
I have a problem with my scroll view I have tow toolbar one on the top and one on the bottom, and these tool bars should be always on the top of other views when I scroll down the last view its behind the bottom bar and not shown this...

Dynamically adding elements to already created relativelayout

android,android-layout,listview,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...

Centering GridView in RelativeLayout

java,android,gridview,relativelayout
I'm trying to center my GridView in a RelativeLayout. I set the GridView's height to wrap_content and gravity of the RelativeLayout is center, but the GridView is still aligned at the top. Here is what I have: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:gravity="center" android:layout_height="match_parent" tools:context="com.example.sixerstrivia.MainActivity" > <GridView android:id="@+id/dashboardGrid"...

First view in RelativeLayout expand to fill remaining space

android,android-layout,listview,relativelayout
I am working on a layout with a cardview, a checkbox and a button with the initial structure as shown in the first image: In this case the listview is not shown until the user clicks an image inside the cardview, so when this happens the dessired structure is like...

set items of LinearLayout at center screen programmatically

android,textview,android-linearlayout,relativelayout
I'm trying to create a grid type view where number of textView boxes will appear at the center of the screen(horizontally). I'm only testing for two rows now. This is my xml file: <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"...

Accessing Android Views in Java files

android,relativelayout
I've designed a RelativeLayout with children elements such as TextView and ImageView. What I want to do is to create a RelativeLayout object from my created RelativeLayout in XML, that way I can access to its children elements and modify them (change image from ImageView and change the text from...

Relative layout - layout_toRightOf

android,relativelayout
I started to convert TableLayout to RelativeLayout. Let's use A, B for columns and 1, 2 for rows. I set A2 BELOW A1 and B2 to RIGHT of A2. The problem is that A2 was displayed over A1 (e.g. in the first row)! I tried align_baseline set to A2 but...

cannot see edittext in relativelayout (offscreen)

android,relativelayout
I have the following relative layout that has a listview with an EditText underneath. I can't see the edittext as the list takes up the whole screen. how can i show both the listview and the edittext on the screen at the same time without scrolling? i've tried numerous layout...

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"...

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...

Android onLongClick bug with TextView

android,textview,relativelayout
I've a strange bug with TextView in RelativeLayout. After setting OnClickListener to RelativeLayout, when I press relativeLayout for long (that is OnLongClick) there appears a popup with button "paste". After pressing "paste" a text from buffer pastes into textView (which is inside RelativeLayout). I'm confused, is it google's side bug,...

How to put Divider in Relative Layout Android?

android,relativelayout
this is my code : <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="48dp" android:background="?android:attr/selectableItemBackground" > <ImageView android:id="@+id/item_icon" android:layout_width="30dp" android:layout_height="20dp" android:layout_centerVertical="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginLeft="12dp"...

Cant figure out how to get center of relativelayout

java,android,relativelayout
I have been struggling with this for the last 2 hours, and I just can't get the answer for this. I want the center of my relativelayout because I want to draw a circle there using a canvas. What I've tried already: ViewTreeObserver.OnGlobalLayoutListener OnStart() Here is my code: @SuppressLint("NewApi") @Override...

How can I set element for entire width of the page? (Android)

android,width,screen,relativelayout,resolution
I want to set the "layoutAtendenteBalao" element for the entire width of the page. I tried to set it to <item name="android:layout_width">match_parent</item>, but it did not work. styles.xml <!--<style name="layoutAtendente"> <item name="android:layout_width">560px</item> <item name="android:layout_height">400px</item> <item name="android:layout_alignParentRight">true</item> <item name="android:layout_alignParentBottom">true</item> </style>--> <style...

RelativeLayout and ListView inside ScrollView

android,android-layout,listview,scrollview,relativelayout
I'm trying to make an scrollable profile for my client for social network. Here's my layout <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swipe_container" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true"> <RelativeLayout android:id="@+id/RelativeLayout1" android:layout_width="fill_parent"...

Android bring view in front of overlay relative layout

android,view,relativelayout
I have a Relative layout with 5 buttons on the bottom. When you click and hold on one of these buttons it makes another invisible relative layout visible which overlays the whole screen. I want the button that was clicked to make the overlay visible to remain visible with the...

Android relative layout, right align a textview below another textview

android,relativelayout,right-align
I've been struggling with this problem in layout for sometime now. To make things simpler, I've a screenshot. I want to right align that textview which has content "3 hours ago" to the right. For this TextView I've layout_below property set to the Linearlayout above(contains two textviews which has contents...

Layout occupies more than desired

android,android-layout,relativelayout
I want an included RelativeLayout acts like footer but I don't get it like this and that's what I get. And that'S what I'd like to get. I copy my Layouts so that you can say me what I'm making wrong Main xml <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout...

Move Android Toolbar To Top Of Relative Layout

java,android,relativelayout,android-toolbar
Hi Guys I am trying to put my button in the center but keep my toolbar at the top at the moment both is in the middle because of the gravity center is there a way to do this without using padding attributes otherwise it will look different on other...

Spacing between two buttons in RelativeLayout in Android xml

android,android-layout,relativelayout
I have a relative layout that has two buttons. I'm trying to set the relative positions of these two dynamically so that on different screen sizes, it looks same. The position of the layout is getting set correctly basing on screen size but the spacing between the buttons is not...

Looking for some Android layout advice

android,android-linearlayout,relativelayout
I have an issue where I need to add several (>20) to a layout at run time and the buttons can be 2 different widths and 2 different heights. I dont know the exact size of these buttons at design time as the minimum size will be determined by the...

Adjusting layout of android activity to fit all screens and always display all information

java,android,xml,android-linearlayout,relativelayout
I have the above layout in my application, however I am using a Note 3 as the test device and whenever I make the design it's too big for most other phones. Here is my XML file. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:background="@drawable/backrepeat" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"...

TextView on top of ImageView in Android

android,android-layout,relativelayout
I am trying to insert a textView on top on ImageView. Image is a circle and inside relativeLayout. I am not able insert the TextView in the center of Circle. Snapshot: Please take a look at the snapshot and the code. <RelativeLayout android:id="@+id/circlenumberlayout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/layoutbackground" > <ImageView android:id="@+id/numberCircle" android:layout_width="40dp"...

Android ImageView scaling confict

android,imageview,relativelayout,scaling,bounds
I am creating ImageView in code: ImageView vlogo = new ImageView(v.getContext()); RelativeLayout.LayoutParams vlogoParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); vlogoParams.addRule(RelativeLayout.ALIGN_TOP,tv_visitor.getId()); vlogoParams.addRule(RelativeLayout.ALIGN_LEFT, tv_visitor.getId()); vlogoParams.addRule(RelativeLayout.ALIGN_BOTTOM, tv_visitor.getId()); vlogo.setLayoutParams(vlogoParams); vlogo.setImageResource(R.drawable.star);...

How can I place Button or TextView at the absolute bottom in RelativLayout?

android,xml,android-layout,textview,relativelayout
There seems to be some hidden padding in the RelativLayout, I'm I right? I've got this TextView: <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="@color/green" android:text="LOG IN"/> in a RelativeLayout. What I cant understand is why android:layout_alignParentBottom="true" doesn't place the TextView all the way down. ref image: Is there any way to remove...

Why my element is not staying at the bottom as supposed?

android,xml,android-layout,relativelayout
I have this layout xml file: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true"> <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:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin"...

How to achieve this layout in Android?

android,button,layout,relativelayout
How can I get this layout in android using RelativeLayout? Not matter what I try, the top 2 buttons don't show up as aspected. Below I have provided a screenshot of what I want, what I attempted and the output of my attempt. Please can anyone help me out. Thanks....

Programatcally remove margin from FrameLayout with LayoutParams

android,relativelayout,classcastexception,framelayout
I have a FrameLayout that looks like this: <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <FrameLayout android:layout_marginTop="56dp" android:layout_marginBottom="50dp" android:id="@+id/main_frag" android:layout_width="match_parent" android:layout_height="match_parent" /> // other stuff </RelativeLayout> However when I change the margins programitcally I get a ClassCastException. FrameLayout fl = (FrameLayout) findViewById(R.id.main_frag); FrameLayout.LayoutParams params =...

How to fill entire ImageView with a icon?

android,xml,imageview,relativelayout
I have an ImageView in RelativeLayout. Problem is my icon is not filling all the space in the ImageView. Its padding inside from all the direction. I found some solution and tried every possible combination, but its not changing a bit. My icon regulation 256*256. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"...

RelativeLayout programmatically margins not working

android,relativelayout,padding,margins
LinearLayout usersPlaceholder = Main.lay_found_users; //Found Users Placeholder //RelativeLayout Params RelativeLayout userlay = new RelativeLayout(mCtx); //Create new Element userlay.setBackgroundResource(R.drawable.btn_useritem); //Background userlay.setGravity(RelativeLayout.CENTER_HORIZONTAL); //Gravity userlay.setClickable(true); //Clickable RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, dp(80)); relativeParams.setMargins(dp(80), dp(80), dp(80),...