Possible overdraw: Root element paints background - android-layout

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.

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.

Design Android dev screen sizes

Hi I need some advice/help
I am designing a app for educational purposes, but battling with different screen sizes.
I am using Android studio to create the screen layouts.
What I did so far works well up and until a point.
I have tried to use constraint layout / Linear layout and relative layout but all have the same issues.
I create my main layout as normal, and then I create new layout resource files with the same activity name but with different densities.
But for some odd reason some of my test phones picks up the certain density layout but is completely out of proportion, even though it looks correct on the layout on the IDE but the minute it is ported to the phone its out.
What would be the best way to create layouts that can cater for all layouts?
here is an example of the layout I have
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".login.LoginActivity"
android:background="#drawable/background"
android:padding="10dp">
<TextView
android:id="#+id/tv_appName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="250dp"
android:layout_marginEnd="8dp"
android:text="#string/app_name"
android:textColor="#color/colorAccent"
style="#style/Base.TextAppearance.AppCompat.Headline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:textAlignment="center"
android:textStyle="bold"
android:textSize="28dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="50dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tv_appName"
android:background="#drawable/input_shape"
android:padding="15dp"
android:textColorHint="#color/colorAccent"
android:textColor="#color/colorAccent"
android:id="#+id/edittext1"
android:singleLine="true"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="50dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/edittext1"
android:background="#drawable/input_shape"
android:padding="15dp"
android:textColorHint="#color/colorAccent"
android:textColor="#color/colorAccent"
android:id="#+id/edittext2"
android:singleLine="true"/>
<Button
android:id="#+id/btn_button1"
android:layout_width="134dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_constraintStart_toStartOf="#+id/edittext2"
app:layout_constraintTop_toBottomOf="#+id/edittext2"
android:background="#drawable/btn_shape"
android:text="Button 1"/>
<Button
android:id="#+id/btn_button2"
android:layout_width="134dp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:layout_constraintEnd_toEndOf="#+id/edittext2"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#+id/btn_button1"
app:layout_constraintTop_toBottomOf="#+id/btn_button1"
android:background="#drawable/btn_shape"
android:text="Button 2"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
I am pretty sure that you are using a fixed size for your views.
Never use a fixed size for a view. If you are using a ConstraintLayout then set the layout_width and layout_height of any view to either 0dp (which will make the view as big as it can be as long as it doesn't go past the constraints) or wrap_content (which will automatically make the view only the size it needs). On other layouts instead of using 0dp for making the view as big as it can be, use match_parent. wrap_content does the same thing in every layout.

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);

Android UI: how to align a TextView and two radiobuttons to occupy 1/3rd parent each?

I'm sure it's very simple and I'm just being stupid, but I've tried numerous variants and still can't get it working. What's worse - these 3 components are aligned exactly the way I want in the graphical editor in Eclipse, but not on the real device. I only get to align it to 50% for TextView and RadioGroup.
The XML goes like this currently (here I presumed RadioGroup is kind of LinearLayout):
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
style="#style/ButtonStyle"
android:layout_width="wrap_content"
android:text="#string/CC_Direction_caption" />
<RadioButton
android:id="#+id/rb_toCamera"
style="#style/ButtonStyle"
android:text="#string/CC_Backwards_Caption" />
<RadioButton
android:id="#+id/rb_toInfinity"
style="#style/ButtonStyle"
android:text="#string/CC_Forwards_Caption" />
</RadioGroup>
And the ButtonStyle is:
<item name="android:layout_width">0dip</item>
<item name="android:layout_height">70dp</item>
<item name="android:layout_weight">1</item>
And all this is inside a TableRow.
Use android:layout_centerVertical="true" in your TextView.
Below is a sample:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<TextView
android:id="#+id/typeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="GroupBox Label"
android:textColor="#color/black"
android:textSize="14dp" />
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:layout_alignParentRight="true"
android:gravity="center"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Radio 1 Text"
android:textColor="#color/blue" />
<RadioButton
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio 2 t"
android:textColor="#color/blue" />
</RadioGroup>
</RelativeLayout>
Try adding android:layout_weight="1" to all three elements. This specifies the relative weight every element has to the others. The higher this value is the less weight the element gets.
oh, and wrap everything in a linear layout (didn't see you didn't add a layout first).
You should use a Linear Layout with weights on your elements which will make it pretty easy to achieve what you want.
Check the docs for info on Linear Layout and weights.
http://developer.android.com/guide/topics/ui/layout-objects.html
Try changing layout_width to "wrap_content" for radio buttons as well. You have already done it for the text field.

Relative Layout Android

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

Resources