EditText in Layout not full width - android-layout

I have problem with xml. Why my EditText doesn't show for full screen width? It showing about 80% of screen width, but not all..
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#color/colorGray"
android:layout_weight=".35" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal|vertical" >
<LinearLayout
android:id="#+id/rightCont"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="test" />
</LinearLayout>
</HorizontalScrollView>
</ScrollView>

Because the EditText is wrapped in a ScrollView wich takes 0.35 weight of the screen. So it will expand until it reaches the boundaries of its parent ViewGroup.
To test this, change the weight of ScrollView to 1:
android:layout_weight="1"

beside what Andy Res said, a scrollview in a scrollview is not recommended. newer android versions can handle that but older one will have trouble determining which scrollview should scroll on touch events.
Also a LinearLayout with wrap_content around the EditText with fill_parent should result in a pure wrap_content behavior of the EditText, too.
You should rethink your layout.

Related

ScrollView and text

How can I make my screen scroll?
How to use ScrollView? At my activity, in it there is a picture and the text, it is necessary for me that at movement downwards or upwards the screen scroll.
The ScrollView XML resource is fairly easy to use and powerful. Just wrap whatever content you want to be scrollable in the XML with the ScrollView tags and the rest will be taken care of for you. Simple example:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:background="#color/colorPrimary"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/yourID"
android:layout_weight="1" />
...
</LinearLayout></ScrollView>
This example shows a LinearLayout filled with whatever you need (TextView in this case) that will scroll on screen when it has to.

Align LinearLayout over LinearLayout inside a RelativeLayout

I'm having a struggle understanding how to align layers one over another in the xml file.
I searched for a solution but couldn't find one for my needs.
I have two LinearLayout inside a RelativeLayout. The first LinearLayout contains a RecycleView/ScrollView and the second LinearLayout contains some buttons.
I want to set the second LinearLayout over the first LinearLayout, but at the bottom of the RelativeLayout. See image below.
Here is what I tested (it will extend the first layout and hide the second).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/first"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<LinearLayout
android:id="#+id/second"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="#+id/first"
android:layout_alignParentBottom="true"
app:layout_gravity="bottom">
</LinearLayout>
</RelativeLayout>
Do you have any idea how to achieve this?
PS. I don't want to use a BottomNavigationView instead of the second LinearLayout.
I managed to find a solution for my issue.
I changed the first LinearLayout with a FrameLayout and everything works as it should. Please keep in mind that the second LinearLayout must stay under the FrameLayout. Cheers!

how to center an image horizontal and vertical inside an edit text in android xml

Something like this please.
I'm new to android, and I am trying to center the image and hint both vertical and horizontal. If anyone can help, I will really appreciate it.
You can't put ImageView inside of an EditText.
You can, instead, put EditView and TextView inside RelativeLayout and center them, like this:
<?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:orientation="vertical">
<EditText
android:id="#+id/my_edit_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:gravity="center"
android:text="This is some edit text" />
<ImageView
android:id="#+id/my_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/com_facebook_button_icon_blue" />
</RelativeLayout>
Since we put EditText width and height to match RelativeLayout, it would appear as if the ImageView is inside of an EditText.
If you want to put text under image just add this line to TextView: android:layout_below="#+id/my_image_view".

change text position to bottom left on screen rotate android

I have to display a text (id- text_view in the code below)at the bottom left of the screen. Find below the code snippet for the text.
<?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="match_parent"
android:layout_gravity="center" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal" >
<TextView
android:id="#+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|bottom"
android:text="SampleText"
android:textColor="#android:color/darker_gray" />
</FrameLayout>
<RelativeLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ProgressBar
android:id="#+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_marginBottom="14dip"
android:layout_marginLeft="30dip"
android:layout_marginRight="30dip"
android:layout_marginTop="14dip"
android:orientation="vertical" />
</RelativeLayout>
It is coming at bottom left but for only Portrait mode. When i rotate screen to landscape mode the text remains there, It should also be rotated to Bottom left of the screen.
Please help me how to achieve this on screen rotation
1:- First Change the FrameLayout to RelativeLayout.
2:- Set layout_gravity of textview to left|bottom.

scrollbar not showing in edittext

I am trying to add a box for entering text. This box should have a small scroll bar on the side. Using this piece of code, what I get is a blank line in which I can enter multiple lines of text. Would anyone know how I could get the box with a scrollbar?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ScrollView
android:layout_height="200dp"
android:layout_width="match_parent">
<EditText
android:id="#+id/event_description"
android:hint="#string/hint_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:textColor="#02960B"
android:textSize="14sp" />
</ScrollView>
EditText inside scrollview will not show you the scroll bar. To show scroll bar for edittext use the following code in yout EditText field for this you don't need to use scrollview you can get rid of it.
android:inputType="textMultiLine"
ScrollView can show scroll bar only if it contain more elements than its height size
A typical Exampl of EditText with scrollbar:
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_alignLeft="#+id/search_query"
android:layout_alignParentBottom="true"
android:inputType="textMultiLine" >
</EditText>

Resources