Hello i have an activity which contains the following elements
this is my xml layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#dddddd">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#dddddd">
<TextView android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="title"
android:textSize="#dimen/checkout_title"
android:textColor="#858585"
android:textStyle="bold"
android:layout_margin="10dp" />
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="474dp"
android:layout_below="#+id/title"
android:layout_marginBottom="10dp"></android.support.v4.view.ViewPager>
<com.pockee.views.CirclePageIndicator android:id="#+id/indicator"
android:padding="0dp"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="#+id/pager"
app:pageColor="#858585"
app:fillColor="#f19201" />
<LinearLayout android:layout_below="#+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip"
android:background="#80000000"
android:layout_margin="10dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Value:"
android:textColor="#color/white" />
<EditText
android:id="#+id/value1"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#color/white"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:inputType="number" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dip"
android:text="Value2:"
android:textColor="#color/white" />
<EditText
android:id="#+id/value2"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:password="true"
android:background="#color/white"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:inputType="number" />
<Button
android:id="#+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:text="OK"
android:background="#f19100"
android:textColor="#color/white"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
in my manifest i'm using
android:windowSoftInputMode="adjustResize|stateVisible"
the problem is that the number keyboard overlaps edit text by 10 pixels
any ideas on this issue?
I see you have a relative layout wrapping your linear layout, yet both your linearLayout and relative layout have a margin of 10dp. Try editing the inner value 'LinearLayout' margin to 0 or changing margin altogether i.e use bottom-margin:0 instead of margin and reloading.
Related
Here is my xml code, it has an ImageView which stands before LinearLayout id = "linearLayout2" :
<?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">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1"
android:background="#drawable/border"
android:paddingBottom="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/ic_swap"
android:layout_gravity="center_vertical" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2"
android:paddingBottom="5dp"
android:layout_marginRight="5dp">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fromStationField"
android:completionThreshold="1"
android:hint="From"
android:textAlignment="textStart"
android:gravity="left|start"
android:layout_gravity="left" />
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toStationField"
android:completionThreshold="1"
android:hint="To"
android:background="#android:color/transparent"
android:paddingRight="4dp"
android:paddingLeft="4dp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
What I want to do is to make an ImageView stands after the LinearLayout id = "linearLayout2" like I show in an image bellow.
How to do this using only xml ?
One solution could be inside of linearLayout1 to move the ImageView after linearLayout2. Then set linearLayout1's width to match_parent and the sibling views width to 0dp. Lastly, use layout_weight to achieve the proportion of size you want for the ImageView and LinearLayout2.
<?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">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/border"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:weightSum="10">
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="9"
android:orientation="vertical"
android:paddingBottom="5dp">
<AutoCompleteTextView
android:id="#+id/fromStationField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:completionThreshold="1"
android:gravity="left|start"
android:hint="From"
android:textAlignment="textStart" />
<AutoCompleteTextView
android:id="#+id/toStationField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:completionThreshold="1"
android:hint="To"
android:paddingLeft="4dp"
android:paddingRight="4dp" />
</LinearLayout>
<ImageView
android:id="#+id/imageView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:src="#android:drawable/ic_swap" />
</LinearLayout>
</RelativeLayout>
In the layout below, I'm using negative margins in the ImageView and a positive margin in the LinearLayout container left of ImageView so that we don't need to use layout_weight property and can keep using match_parent. For this you need to fix the size of your ImageView. Check this code out:
<?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">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout1"
android:background="#drawable/border"
android:paddingBottom="5dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout2"
android:layout_marginRight="55dp"
android:paddingBottom="5dp">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fromStationField"
android:completionThreshold="1"
android:hint="From"
android:textAlignment="textStart"
android:gravity="left|start"
android:layout_gravity="left" />
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/toStationField"
android:completionThreshold="1"
android:hint="To"
android:background="#android:color/transparent"
android:paddingRight="4dp"
android:paddingLeft="4dp" />
</LinearLayout>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/imageView"
android:src="#drawable/ic_swap"
android:layout_marginLeft="-55dp"
android:layout_gravity="center_vertical" />
</LinearLayout>
</RelativeLayout>
I wanted to make a layout with 3 LinearLayouts. In the 2nd LinearLayout I would have a ListView and the 3rd LinearLayout I would have an EditText and Button at the bottom. This was my attempt:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/view_post"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:background="#color/com_facebook_blue">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/view_status"/>
</LinearLayout>
<LinearLayout
android:id="#+id/view_comments"
android:layout_below="#+id/view_post"
android:layout_width="match_parent"
android:layout_height="250dp">
<ListView
android:id="#+id/lv_comments_feed"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
<LinearLayout
android:layout_below="#+id/view_comments"
android:id="#+id/send_message"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<EditText
android:id="#+id/write_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:gravity="top|left"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<Button
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
Now the design looks great but when I load the app on my phone, I have 2 problems:
I don't want to hardcode the LinearLayout heights. I have looked into layout_weight but I can't seem to have these layout_weights work without running into the 2nd problem below:
When I click the EditText, the EditText is hidden even though I have declared android:windowSoftInputMode="adjustResize|stateHidden" in my activity and I'm not sure why that's happening. Also, the EditText and Button are not directly at the bottom of the screen which is what I would want. Any help is appreciated, thanks!
you don't need to add listview as child of linear layout. and avoid fill_parent & use match_parent. if first linear layout is only for textview then don't use it inside of linearlayout. or only use wrap_content instead of a specific layout_height
Here i made some changes hope it will work
<?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">
<LinearLayout
android:id="#+id/view_post"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#222dc9">
<TextView
android:id="#+id/view_status"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/send_message"
android:layout_below="#id/view_post"
></ListView>
<LinearLayout
android:id="#+id/send_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<EditText
android:id="#+id/write_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_weight="5"
android:gravity="top|left"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<Button
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:gravity="center"
android:text="send"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
and use in Manifest with activity name is
android:windowSoftInputMode="adjustPan"
<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"
tools:context=".MainActivity">
<RelativeLayout
android:id="#+id/view_post"
android:layout_width="match_parent"
android:background="#color/material_grey_300"
android:padding="5dp"
android:layout_height="wrap_content">
<TextView
android:id="#+id/view_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/view_comments"
android:layout_above="#+id/send_message"
android:layout_below="#+id/view_post"
android:layout_width="match_parent"
android:background="#color/material_deep_teal_200"
android:padding="10dp"
android:layout_height="match_parent">
<ListView
android:id="#+id/lv_comments_feed"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</RelativeLayout>
<LinearLayout
android:id="#+id/send_message"
android:background="#color/material_blue_grey_800"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<EditText
android:id="#+id/write_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textMultiLine"
android:scrollHorizontally="false" />
<Button
android:id="#+id/send_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:layout_weight="1"
android:text="send" />
</LinearLayout>
</RelativeLayout>
I have a scrollView (this is a solution to support landscape computability)
and in it one child- linearLayout.
I want to pose a button at the bottom of a screen.
layout_height = match_parent is problematic as the scroll can be infinite.
How can I do this, to be compatible to all screen resolution?
this is my xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.m"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue_bg" >
<LinearLayout
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<com.m.view.text.mTextView
android:id="#+id/verifyHeaderText"
style="#style/textOnBg"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginTop="50dp"
android:text="ENTER VERIFICATION CODE"
android:textAllCaps="true"
android:textColor="#android:color/white"
app:font_type="varela" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:paddingBottom="5dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="5dp" >
<LinearLayout
android:id="#+id/inputBox"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:background="#drawable/input_box_idle"
android:orientation="horizontal" >
<EditText
android:id="#+id/verificationCodeEditText"
style="#style/textOnBg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:hint="- - - - -"
android:inputType="number"
android:maxLength="5"
android:textColor="#00bcfe"
android:textSize="25dp"
android:textStyle="italic" >
</EditText>
</LinearLayout>
</LinearLayout>
<Button
android:id="#+id/continueButton"
style="#style/textOnBg"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:background="#drawable/btn_selector"
android:text="Continue"
android:textColor="#00bcfe"
android:textSize="16dp"
android:textStyle="italic" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
this is the result on wide-screen
The button is in the bottom of the scroll which spans 3/4 of the whole screen
Add android:fillViewport="true" to your scrollview:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.m"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue_bg"
android:fillViewport="true" >
Apply this to your layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Your scroll view -->
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_marginBottom="#dimen/ar_button_height"
android:gravity="center" >
<Button
android:id="#+id/button_at_bottom"
android:layout_width="match_parent"
android:layout_height="#dimen/ar_button_height"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="horizontal"
android:showDividers="middle" >
</Button>
</ScrollView>
</RelativeLayout>
Not sure if there is a better solution, but you could put your scroll view inside a relative layout and have your button outside the scroll view and set android:layout_alignParentBottom="true" on the button
If you want to set the button at the bottom you need to implement your layout with weight.
First of all the scrollview can only have one child layout inside it.
Secondly add your content layout inside the child layout of it, set the layout_height to 0dp, and do remember to set the weight to 1.
And at last add your button at the bottom of your content layout and set its height and set the weight to be 0.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/scrollMain"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="always"
android:background="#00000000"
android:scrollbars="none">
<LinearLayout
android:overScrollMode="always"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:background="#FFFFFF"
android:paddingTop="5dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
<Button android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_weight="0" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<com.m.view.text.mTextView
android:id="#+id/verifyHeaderText"
style="#style/textOnBg"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginTop="50dp"
android:text="ENTER VERIFICATION CODE"
android:textAllCaps="true"
android:textColor="#android:color/white"
app:font_type="varela" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:paddingBottom="5dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="5dp" >
<LinearLayout
android:id="#+id/inputBox"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:background="#drawable/input_box_idle"
android:orientation="horizontal" >
<EditText
android:id="#+id/verificationCodeEditText"
style="#style/textOnBg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:hint="- - - - -"
android:inputType="number"
android:maxLength="5"
android:textColor="#00bcfe"
android:textSize="25dp"
android:textStyle="italic" >
</EditText>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<Button
android:id="#+id/continueButton"
style="#style/textOnBg"
android:layout_width="250dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:background="#drawable/btn_selector"
android:text="Continue"
android:textColor="#00bcfe"
android:textSize="16dp"
android:textStyle="italic" />
USe your button here
You can use scrollView inside relativeLayout to fix your button at bottom:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/radialback">
<ScrollView android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_below="#+id/top_header"
>
<EditText
android:id="#+id/editmessage"
android:layout_margin="2dp"
style="#style/editView"
android:inputType="textMultiLine"
android:digits="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 _-.,()"
android:maxLength="500"
/>
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/submitbutton"
android:text="#string/submitbutton"
style="#style/submitView"
android:layout_alignParentBottom="true" />
</RelativeLayout>
I have a problem in my android layout.
I have an Image as following contains two parts:
(green border) will contains a descriptive meaning
(red border) I have to position a text in this part to be centered
I want the text to be in the bottom 1/3 of the image.
I have tried to make it programmatically but it doesn't work as I can't get (x, y, w, h) of an Image except it has rendered to the screen.
I have tried also the following code:
<RelativeLayout
android:id="#+id/item1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1" >
<ImageView
android:id="#+id/item1_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="#drawable/item1_icon" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="3" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2" >
</LinearLayout>
<TextView
android:id="#+id/item1_title"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center"
android:maxLength="10"
android:singleLine="true"
android:text="My Day"
android:textColor="#android:color/white"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
How can I do that?
Note that the layout_weight attribute is assigned to the RelativeLayout:
<RelativeLayout
android:id="#+id/item1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1" >
It won't work this way. Only a LinearLayout can have a layout_weight attribute. For RelativeLayout it is ignored.
I guess that you forgot to add this namespace to root view of your layout:
xmlns:android="http://schemas.android.com/apk/res/android"
And also I guess your problem will be solved if add it to your code.I added that to your code and try it.It was true.This is it's all:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/item1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1" >
<ImageView
android:id="#+id/item1_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="3"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#android:color/white" >
</LinearLayout>
<TextView
android:id="#+id/item1_title"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center"
android:maxLength="10"
android:singleLine="true"
android:text="My Day"
android:textColor="#android:color/white"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
This should work
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/item1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp">
<ImageView
android:id="#+id/item1_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="#android:color/white" >
</LinearLayout>
<TextView
android:id="#+id/item1_title"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center"
android:maxLength="10"
android:singleLine="true"
android:text="My Day"
android:textColor="#android:color/white"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
I'm trying to create RelativeLayout with many widgets and I want to be able to scroll it vertically and horizontally.
At first, I made it to scroll only vertically with that xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical" >
<ScrollView
android:id="#+id/layoutPostWriteScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_marginRight="5dp"
android:fitsSystemWindows="true"
android:gravity="center" >
<TextView
android:id="#+id/layoutPostWriteCtrlLabelTheme"
style="#style/News.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Тема" />
<EditText
android:id="#+id/layoutPostWriteCtrlTheme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layoutPostWriteCtrlLabelTheme"
android:inputType="text" />
<LinearLayout
android:id="#+id/layoutPostWriteEmbeddedMediaLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteCtrlTheme"
android:gravity="left"
android:orientation="vertical" />
<Button
android:id="#+id/layoutPostWriteAddMediaButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteEmbeddedMediaLayout"
android:onClick="onAddMediaClick"
android:text="+ Добавить медиафайл" />
<TextView
android:id="#+id/layoutPostWriteCtrlLabelContent"
style="#style/News.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteAddMediaButton"
android:text="Содержание" />
<EditText
android:id="#+id/layoutPostWriteCtrlContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteCtrlLabelContent"
android:gravity="top"
android:inputType="textMultiLine"
android:lines="10"
android:scrollbars="vertical"
android:singleLine="false" />
<Button
android:id="#+id/layoutPostWriteCtrlSave"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_below="#id/layoutPostWriteCtrlContent"
android:background="#drawable/btn_save"
android:onClick="onClickSendPost" />
</RelativeLayout>
</ScrollView>
My activity looks like that:
Everything's allright and that activity scrolls vertically.
But then I tried to add horizontalScrollView like that:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:orientation="vertical" >
<ScrollView
android:id="#+id/layoutPostWriteScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:fitsSystemWindows="true">
<HorizontalScrollView
android:id="#+id/layoutPostWriteHScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="fill"
android:fillViewport="true"
android:fitsSystemWindows="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_marginRight="5dp"
android:fitsSystemWindows="true"
android:gravity="center" >
<TextView
android:id="#+id/layoutPostWriteCtrlLabelTheme"
style="#style/News.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Тема" />
<EditText
android:id="#+id/layoutPostWriteCtrlTheme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layoutPostWriteCtrlLabelTheme"
android:inputType="text" />
<LinearLayout
android:id="#+id/layoutPostWriteEmbeddedMediaLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteCtrlTheme"
android:gravity="left"
android:orientation="vertical" />
<Button
android:id="#+id/layoutPostWriteAddMediaButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteEmbeddedMediaLayout"
android:onClick="onAddMediaClick"
android:text="+ Добавить медиафайл" />
<TextView
android:id="#+id/layoutPostWriteCtrlLabelContent"
style="#style/News.Caption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteAddMediaButton"
android:text="Содержание" />
<EditText
android:id="#+id/layoutPostWriteCtrlContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layoutPostWriteCtrlLabelContent"
android:gravity="top"
android:inputType="textMultiLine"
android:lines="10"
android:scrollbars="vertical"
android:singleLine="false" />
<Button
android:id="#+id/layoutPostWriteCtrlSave"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_below="#id/layoutPostWriteCtrlContent"
android:background="#drawable/btn_save"
android:onClick="onClickSendPost" />
</RelativeLayout>
</HorizontalScrollView>
</ScrollView>
There is no errors in markup but activity now looks like that:
All EditTexts and whole RelativeLayout shrinked. How can I make activity to look like at the first image, but scroll vertical and horizontal? I tried many combinations of layout_width and layout_height, but it seems to not work.
maybe it will helpful for you, there is a Link which describes how to make two dimensional scroll with ScrollView and HorizntalScrollView.