Relative Layout Android - android-layout

I have 6 textviews,3 editboxes and two spinners in a Relativelayout.I am trying to add further editboxes in the app. But the app is not showing the additional boxes.
My code is:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollview"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView
android:id="#+id/EditText01"
android:text="#string/type1"
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:textSize="18sp"
android:layout_toLeftOf="#+id/Button01"
android:layout_height="wrap_content"></TextView>
<EditText
android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"></EditText>
<TextView
android:id="#+id/EditText02"
android:text="#string/type2"
android:layout_alignParentLeft="true"
android:layout_below="#id/EditText01"
android:layout_width="fill_parent"
android:textSize="18sp"
android:layout_toLeftOf="#+id/Button01"
android:layout_height="wrap_content"></TextView>
<EditText
android:id="#+id/Button02"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/Button01"
android:layout_height="wrap_content"></EditText>
<TextView
android:id="#+id/EditText03"
android:text="#string/type3"
android:layout_alignParentLeft="true"
android:layout_below="#id/EditText02"
android:layout_width="fill_parent"
android:textSize="18sp"
android:layout_toLeftOf="#+id/Button01"
android:layout_height="wrap_content"></TextView>
<EditText
android:id="#+id/Button03"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/Button02"
android:layout_height="wrap_content"></EditText>
<TextView
android:id="#+id/EditText04"
android:text="#string/property"
android:layout_below="#id/EditText03"
android:layout_width="fill_parent"
android:textSize="18sp"
android:layout_height="wrap_content"></TextView>
<Spinner
android:id="#+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/Button03"
android:prompt="#string/property"></Spinner>
<TextView
android:id="#+id/EditText05"
android:text="#string/propage"
android:layout_below="#id/spinner"
android:layout_width="fill_parent"
android:textSize="18sp"
android:layout_height="wrap_content"></TextView>
<Spinner
android:id="#+id/widget"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/EditText05"
android:prompt="#string/propage"></Spinner>
<TextView
android:id="#+id/EditText06"
android:text="#string/income"
android:layout_alignParentLeft="true"
android:layout_below="#+id/widget"
android:layout_width="fill_parent"
android:textSize="18sp"
android:layout_toLeftOf="#+id/Button04"
android:layout_height="wrap_content"></TextView>
<EditText
android:id="#+id/Button04"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"></EditText>
</RelativeLayout>
</ScrollView>
The last editbox or any element further added is not showing in the app.
Please help.

Can you please update the correct and complete xml file content?
Also, from the GUI designer's point of view, I think these many controls are atrocious on a limited display. Though you have used a ScrollView, I would suggest to rethink over your GUI design.

I think they are actually showing but they may be overlapping previous edit boxes. As a test, I replaced all the #strings with sequential numbers as strings and added an extra edit box to the end of your code and it does appear in the layout but overlaps the last one. Try doing the same thing as a test and you will see what I mean. Hope it goes well for you.
Cheers,

Things that strike me as odd about the last EditText:
It's ID'd as a button. Consider using Button if it's a button.
It has no content, unless it's set programmatically. So wrap_content
on the width will give it a width of 0 (so it's invisible).
It's in a RelativeLayout, but you haven't said which other element it should
be placed relative to. I think the default is that it'll overlap
elements, and just go at the top. But because it has a width of 0,
you won't even be able to see it there.
Hope this helps. Death to RelativeLayout. (Not really, it's useful, but I hate it).

Related

Scrollview overlaps part of the text

I need help.
At work, I was given a task to figure out why ScrollView overlaps part of the text. The layout is multi-layered, and I think the problem lies in this. I'm new to android studio and it's still hard for me to understand the relationships of all objects.
all the XML is here https://docs.google.com/document/d/1PaGIWPn2w6ubZraVpQfq8Rrqo0uCWYOiIbxnCWaIKTQ/edit?usp=sharing
below is a part of the code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|left|center_vertical"
android:orientation="vertical">
<TextView
android:id="#+id/tvMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:textColor="#color/mainBlackColor"
android:textSize="24dp"
tools:text="Сообщение" />
<TextView
android:id="#+id/tvDetails"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/red"
android:lines="3"
android:paddingStart="3dp"
android:paddingLeft="3dp"
android:paddingTop="2dp"
android:paddingEnd="3dp"
android:paddingRight="3dp"
android:paddingBottom="2dp"
android:textColor="#color/mainTextColor"
android:textSize="18dp"
android:visibility="gone"
app:autoSizeMaxTextSize="18dp"
app:autoSizeMinTextSize="10dp"
app:autoSizeStepGranularity="4dp"
app:autoSizeTextType="uniform"
tools:text="Детали"
tools:visibility="visible" />
</LinearLayout>
</ScrollView>
Add android:scrollbarStyle="outsideOverlay" and padding_horizontal to your scrollView. This should solve your issue.

How can I set my imageviews to fill linearlayout with equal spacing?

I have four image icons that I need to display with Imagebutton or Imageview. The problem is when I use the following code, they all are aligned left leaving an empty space to the right.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/sale"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/shirt"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/women"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:src="#drawable/technology"
android:layout_weight="1"/>
</LinearLayout>
How can I get them equally distributed on the linearlayout so that they fill the whole width?
I just managed to fix the issue. It seems I was needed to use android:layout_width"fill_parent" instead of android:layout_width="wrap_content". I tried this after #grwww suggested android:layout_gravity="fill" which was not the needed attribute. Then I got to learn about fill_parent

can't get android custom dialog box to size properly

I'm trying to create a custom dialog box but it's both making it as wide as the screen (minus padding) but more importantly it's adding about an inch to the top in white (the background colour is red) above the first textview. What I want is a dialog box just as big as it needs to fill the content.
If I change any layout from fill_parent to wrap_content I get the contents about the size of the image and everything else (i.e. the text) is truncated.
What am I doing wrong?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/customdialog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/titledialog"
android:orientation="vertical" >
<TextView
android:id="#+id/textTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/titleback"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/title" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="15dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="24dp"
android:paddingTop="48dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/textContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="TextView" />
</LinearLayout>
<Button
android:id="#+id/buttonCustomDialogOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Close" />
I found the answer here
Android: How to create a Dialog without a title?
Apparently the top blank bit is the title of the layout and you cannot get rid of it unless you use an AlertDialog and not a Dialog.
ah, thanks for the update.
Android Dialog: Removing title bar
you can do it like this
Dialog dialog = new Dialog(context, R.style.FullHeightDialog);
(OR Try This)
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

Possible overdraw: Root element paints background

In my application, it appears this warning on the lints of Android:
Possible overdraw: Root element paints background #drawable/main with
a theme that also paints a background (inferred theme is #android:style/Theme)
I wanna know how to correct this mistake, cause after checking and checking on internet, I just found that it is decreasing application speed cause it reload two times the background to put this source.
This is the source of my layout.xml:
<?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="match_parent"
android:background="#drawable/main"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="120dp"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:text="#string/alta1"
android:textColor="#000"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true"
android:text="#string/alta2"
android:layout_marginLeft="20dp"
android:textColor="#000"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="#+id/continuaralta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView2"
android:layout_marginRight="50dp"
android:layout_marginTop="36dp"
android:textStyle="bold"
android:background="#drawable/boton"
android:text="#string/continuar" />
<Button
android:id="#+id/saliralta"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/continuaralta"
android:layout_alignBottom="#+id/continuaralta"
android:layout_marginRight="15dp"
android:layout_toLeftOf="#+id/continuaralta"
android:background="#drawable/boton"
android:textStyle="bold"
android:text="#string/salir" />
Neil Sainsbury, at http://www.earthtoneil.com/, says that Romain Guy has addressed the underlying issue at http://android-developers.blogspot.com/2009/03/window-backgrounds-ui-speed.html. See Neil's blog and search for your error message. Then, go to http://developer.android.com/guide/topics/ui/themes.html to learn how to apply background themes to the app as a whole and to individual activities.
This approach will at least cause the error message to no longer appear. Hitting the two-arrows icon to refresh the warnings in the lint window after making the fix was necessary in my case.

Android DP toughts?

Can someone please give me directions on this:
I've got a ListView, the adapter got a LinearLayout and in this I got four more LinearLayouts.
Now I read about dp and it is relative to 160, but when I read different examples this number "160" seems to be different on different screens, so how do I work with dp?
I am used to work with % in this cases.
Now I want my four LinearLayouts to be:
55dp
35pd
35pd
35pd
Like if the dp was 160!
But as I mentioned above, this dosen't work on all screens.
Can someone tell me how I should work with this? Directions or a good tutorial or similar?
This is what I have tried, and come up with so far:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="15dip"
android:layout_marginBottom="15dip"
android:paddingTop="15dip"
android:paddingBottom="15dip" >
<LinearLayout
android:orientation="vertical"
android:layout_width="55dp"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="#+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:text="Woho"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="Woho"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:text="Woho"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="35dp"
android:layout_height="wrap_content"
android:gravity="center">
<Button
android:text="Woho"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="Woho"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:text="Woho"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
As per the android documentation, 1 DP = 1 pixel on a 160 DPI screen. If the screen is 240 DPI, then 1.5pixel = 1 DP. the size of one DP is independent of underlying hardware resolution but a function of DPI of the screen.
To your layout question, if you assign a fixed width value to your layout, then it will not look good on larger screen sizes.
Better to use layoutweight to distribute the width between those layouts.

Resources