How I do to roll the text to the bottom? - android-layout

I'm programming on ADK and I got one screen with a text at a huge font so the whole text can't appear on the screen. I want to know to do slide the finger up and see the text below, sliding it as we do with normal texts on Android.

Put your TextView inside ScrollView in XML like:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/txt2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="txt2"/>
</ScrollView>
OR If You don't need to use a ScrollView actually.
Just set the
android:maxLines = "AN_INTEGER"
android:scrollbars = "vertical"
properties of your TextView in your layout's xml file.
Then use:
yourTextView.setMovementMethod(new ScrollingMovementMethod())
in your code.
It scrolls automatically without any issues.

Create a custom listview! Like so : http://www.vogella.com/articles/AndroidListView/article.html#androidlists_overview

Related

Why doesn't the the TextInputLayout follow the width of parent ConstraintLayout?

You can see here that I have a CardView which is the parent of a ConstraintLayout.
Additionally, the CardView layout_width is set to match_parent. And the ConstraintLayout is set to match_parent. That all works because the CardView and ConstraintLayout are the width of the entire layout area.
The Problem
You can also see that I have a TextInputLayout which is the child of the ConstraintLayout. The only setting choice I have for layout_width is match_constraint (shown in following image).
When I choose match_constraint the value automatically gets set to 0dp and the widget ends up being 0dp on screen.
Is This A Bug?
Why doesn't the the TextInputLayout follow the width of the ConstraintLayout (width of entire layout) -- similar to match_parent?
Can you advise the proper way to fix this? Is there a different value that the TextInputLayout's layout_width should be set to?
You should not use match_parent for Views which are children of ConstraintLayout as stated in the documentation:
Important: MATCH_PARENT is not recommended for widgets contained in a ConstraintLayout. Similar behavior can be defined by using MATCH_CONSTRAINT with the corresponding left/right or top/bottom constraints being set to "parent".
What you're missing in your case is the end constraint for your TextInputLayout. To use 0dp (match_constraint) you need to have both constraints specified for that dimension:
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/description_layout"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
If I look at the layout's XML i see the following for the TextInputLayout
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/description_layout"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent">
If I change layout_width like the following (by manually typing the value in):
android:layout_width="match_parent"
Then the layout looks like I expect. This seems to fix the problem. Is it correct?

Is there a way to have ListView to be on the right side of the screen?

I am making an app (for homework) that displays the subject's grades and what the teacher has to say about the student as a String, but but I need the ListView to be on the right hand side of the screen (it needs to support a language from right to left, unlike English left to right) and I couldn't find a way to do it
I tried using layout_gravity="right"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".MainActivity"
android:orientation="vertical">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:id="#+id/subjectLW">
</ListView>
</LinearLayout>
I expected the text inside the ListView stick to the right hand side of the screen but instead nothing happens, there is probably a way of making it happen and I don't know how to do it
Update:
Right now I used android:layout_gravity="end" instead of android:layout_gravity="right" to make the text stick to the right side of the ListView, but I would like the ListView itself to be on the right side of the screen, refer to the pictures below, still clueless on how to do it.
Second Update:
Solution was found, instead of using layout_gravity="right" ListView needed textAlignment="center" and then it updates itself to the corresponding type of language, if it is left-right it will stick to the right size, and if it is right-left it will stick to the right side of the screen.
The Screens current state
How I need it to look like (done with the magic of MS Paint)
You need to set layout_gravity="end" in your ListView item view TextView.

How to place an imageview on the top in android Studio?

As it's shown in the android studio it looks perfectly fine but whenever i run the app on my cell phone it looks like this any idea ,please ?? the app on the phone and the android studio
You are using Relative Layout.
First thing I noticed in your code is that you used margin buttom in Image view which is top of the screen already.So I suggest to not use Margin Buttom in that because relative layout bydefault keep that image on top .So i give you some idea to fix it.
1.)Image is on top so and its Relative layout.
<ImageView
android:id="#id/image" (give any id here)
android:src=""
android:marginleft="" ("Add ur dimensions")
android:marginright=""
android:adjustviewbound="True"/>
2.)Next is Textview.
<TextView
android:id="#id/text"
android:text="Name:Lovely Hamester"
android:layout_below="#+id/image"
android:margintop=""/>
So the main thing i wanna point of is this "Id".Relative Layout directly cant put views line by line like Linear Layout,We need to give command to the view to where it need to place.So thats why we use "layout_below" which instruct Text view to stay after imageview.There are different commands also.Please check that,like "layout_rightof","layout_leftof".
Just give id to every view and command them in Relative layout.Your other code is perfect.Dont use Margin Bottom , because it kept space from bottom which looks perfect in the preview but every Mobile have different size so thats why its not shows perfect in your screen.
just move code imageview to the top
example
<RelativeLayout
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"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<ImageView
android:layout_width="200dp"
android:layout_height="600dp"
android:src="#drawable/test"/>
<ProgressBar
android:layout_width="48dp"
android:layout_height="48dp"
android:id="#+id/progressbar"
android:layout_centerInParent="true"/>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_notes"
android:layout_width="250dp"
android:layout_height="match_parent"
tools:listitem="#layout/item_note"
app:layout_behavior="#string/appbar_scrolling_view_behavior"/>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
android:src="#drawable/button"
app:borderWidth="1dp"
app:elevation="9dp"
android:backgroundTint="#FFFFFF"/>
</RelativeLayout>
The problem as i see it that you have a margin bottom override the layout align Parent Top so if you delete that and leave only :
android:layout_alignParentTop="true"
also it is redundant to call align right and left and bottom , align top will be enough.
i'm sure it will work.

This view is not constrained vertically. At runtime it will jump to the left unless you add a vertical constraint

New Layout editor in Android Studio 2.2 keeps showing this error on views like EditText and Buttons. kindly help.Also, any links that help in onboarding with the new constraint layout would be appreciated.
code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:id="#+id/activity_main"
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="com.set.email.MainActivity"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="81dp">
<TextView
android:text="To:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="7dp"
tools:layout_editor_absoluteY="4dp"
android:id="#+id/textTo"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="24dp"
android:id="#+id/editTo"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"/>
<EditText
android:layout_width="384dp"
android:layout_height="42dp"
android:inputType="textPersonName"
android:ems="10"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="94dp"
android:id="#+id/editSubject"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"/>
<EditText
android:layout_width="384dp"
android:layout_height="273dp"
android:inputType="textPersonName"
android:ems="10"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="179dp"
android:id="#+id/editMessage"
app:layout_constraintLeft_toLeftOf="#+id/activity_main"
tools:layout_constraintLeft_creator="50"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"/>
<Button
android:text="Send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="140dp"
tools:layout_editor_absoluteY="454dp"
android:id="#+id/btnSend"
app:layout_constraintLeft_toLeftOf="#+id/editMessage"
tools:layout_constraintLeft_creator="0"
app:layout_constraintRight_toRightOf="#+id/activity_main"
android:layout_marginEnd="16dp"
tools:layout_constraintRight_creator="0"
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"/>
</android.support.constraint.ConstraintLayout>
From Android Studio v3 and up, Infer Constraint was removed from the dropdown.
Use the magic wand icon in the toolbar menu above the design preview; there is the "Infer Constraints" button. Click on this button, this will automatically add some lines in the text field and the red line will be removed.
Constraint layout aims at reducing layout hierarchies and improves performance of layouts(technically, you don't have to make changes for different screen sizes,No overlapping, works like charm on a mobile as well as a tab with the same constraints).Here's how you get rid of the above error when you're using the new layout editor.
Click on the small circle and drag it to the left until the circle turns green,to add a left constraint(give a number, say x dp. Repeat it with the other sides and leave the bottom constraint blank if you have another view below it.
Edit: According to the developers site, Instead of adding constraints to every view as you place them in the layout, you can move each view into the positions you desire, and then click Infer Constraints to automatically create constraints. more here
Just copy this code to all components that you will drag.
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
example:
<TextView
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:text="To:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="7dp"
tools:layout_editor_absoluteY="4dp"
android:id="#+id/textTo"/>
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
This help me a lot
Go to the Design, right click on your Widget,
Constraint Layout >> Infer Constraints. You can observe that some code has been automatically added to your Text.
Follow these steps:
Right click on designing part > Constraint Layout > Infer Constraints
If Inferring the Constraints still gives you the error, just use this code:
app:layout_constraintBottom_toBottomOf="parent"
You need to drag the EditText from the edge of the layout and not just the other widget. You can also add constraints by just dragging the constraint point that surrounds the widget to the edge of the screen to add constraints as specified.
The modified code will look something similar to this:
app:layout_constraintLeft_toLeftOf="#+id/router_text"
app:layout_constraintTop_toTopOf="#+id/activity_main"
android:layout_marginTop="320dp"
app:layout_constraintBottom_toBottomOf="#+id/activity_main"
android:layout_marginBottom="16dp"
app:layout_constraintVertical_bias="0.29"
Go to the XML layout Text where the widget (button or other View) indicates error, focus the cursor there and press alt+enter and select missing constraints attributes.
for example I have this
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
use RelativeLayout layout like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
Simply switch to the Design View, and locate the concerned widget. Grab the one of the dots on the boundary of the widget and join it to an appropriate edge of the screen (or to a dot on some other widget).
For instance, if the widget is a toolbar, just grab the top-most dot and join it to the top-most edge of the phone screen as shown in the image.
You have to change androidx.constraintlayout.widget.ConstraintLayout to RelativeLayout.

How to align widgets with some position on background, and also display right on different devices?

I'm not a designer but recently, I have been asked to change Login Screen UI for the app of my company.
I have got a background image from a designer. This image is a complete login screen. That means it is a single PNG file with the Input Box (User Name and Password Box) DRAWN on it.
Of course even it looks like a complete Login screen, just put it there won't work since the input boxes are fake.
I tried to put the EditText widgets on it, tried to let it just on the position on the background image and set these two widgets background to none so the user won't see it. However, on difference devices it just displays incorrectly. Sometimes above the "background input box", sometimes below it. Anyway, it just won't fit there.
I wonder if there is a way that could let me solve this problem. Let the widgets will be on that exactly position of the background, no matter how the devices changes.
Here is my layout now, and hope it will help:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainTableLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/pbackground"
android:stretchColumns="1" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="160dp" >
<EditText
android:id="#+id/txtBxPassword"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:ems="10"
android:gravity="center_vertical|center_horizontal|center"
android:height="33dp"
android:password="true"
android:singleLine="true"
android:width="160dp" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/txtBxUserID"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_above="#+id/txtBxPassword"
android:layout_alignLeft="#+id/txtBxPassword"
android:layout_marginBottom="10dp"
android:ems="10"
android:gravity="center_vertical|center_horizontal|center"
android:height="33dp"
android:singleLine="true"
android:width="160dp" />
</RelativeLayout>
</RelativeLayout>
And here are the images I captured from Eclipse, as you can see I put two EditText boxes just at the position of the input boxes on background. But on the real devices, they will be misplaced.
Thank you!
put the linearlayout as base layout instead of relative layout...
and use tablerow layout and place the widgets in it
wisely use android:layout_margin and android:layout_width and android:layout_height
properly...
hope it would help
You should ask your designer to give you files for the individual elements -- e.g. the padlock & head icons on their own, and the shaded box on its own. Convert the box to a Nine-patch and set it as the background drawable of a suitable layout element (i.e. the container layout of each row).
You will also want to have multiple sizes of each image to support different pixel densities.
If you don't do this, you will always have some devices where the screen looks terrible.

Resources