Good day!
I have a ListView with news list, but if the title is very long- he lost on the edge of the screen.
How do I text-wrap to the next line?
I read many posts about this, but can not find solution that works to me.
Here the code:
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
>
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.app.SportNewsReaderApp.NewsActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:textSize="16.5dip"
android:padding="2dip"
android:minLines = "1"
android:maxLines = "100"
android:singleLine = "false"
android:inputType="textMultiLine"
android:scrollHorizontally="false"
android:lines="2"
/>
</LinearLayout>
How do I text-wrap to the next line?
by removing minLines attribute
Related
I want to show the word "STATS" above a Listview containing either 2 or 3 list items. I want the ListView at the bottom edge of the screen and the remaining space to be filled by the "STATS" TextView and the text centered vertically and horizontally. Basically a single word floating lonely in the exact middle of the remaining space.
I cannot do this in the "drag and drop" layout editor because it shows 8 placeholder items in the ListView, so I can't snap to the edges of things properly.
I've got the ListView how I want it, but the "STATS" is causing problems.
I've tried all sorts of things (apart from the right one, obviously). Here's my currently broken layout...
<?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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="uk.co.xxxxxxxxxxx.xxxxxxx.MainActivity"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom"
>
<TextView
android:id="#+id/tv_reboot_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textStyle="bold"
android:textAlignment="center"
android:text="#string/stats"
/>
<ListView
android:id="#+id/lv_app_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/reboot_screen_items"
android:layout_gravity="center_horizontal|center_vertical"
/>
</LinearLayout>
I'm sure it's something trivial to do but its driving me mad.
Try this, it works well
<?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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tv_reboot_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textStyle="bold"
android:textAlignment="center"
android:text="STATE"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center" />
<ListView
android:id="#+id/lv_app_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/reboot_screen_items"
android:layout_gravity="bottom" />
</LinearLayout>
Result
Can you try this?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="uk.co.xxxxxxxxxxx.xxxxxxx.MainActivity"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:id="#+id/tv_reboot_message"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="30sp"
android:textStyle="bold"
android:textAlignment="center"
android:gravity="center"
android:text="STATS"
android:layout_above="#+id/lv_app_info"
/>
<ListView
android:id="#+id/lv_app_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="#array/values"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
/>
</RelativeLayout>
You can use RelativeLayout to fill up the remaining space to show your TextView.
Use gravity and layout_gravity attributes.
Gravity and layout_gravity
I am making an app where there is a custom search bar. I want there to be a search part that is big, a spinner for region selection that is a small square, and a search button that is also a small square.
Here is what I am talking about.
The code I have right now is this:
<LinearLayout 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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText
android:hint="#string/summoner_name"
android:layout_width="wrap_content"
android:layout_weight="75"
android:layout_height="wrap_content"
android:id="#+id/summoner_name"/>
<Spinner
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/regions">
</Spinner>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/search_button"/>
</LinearLayout>
However, this makes the search half the screen, and the button for 2/5's the screen, and the spinner for a smaller ammount. Anyone know how to accomplish this?
Thanks :)
give weight 1 to EditText android:layout_weight="1" , and remove weight tags from other components.
Also you will require to set Spinners width statically, if above doesnt work because of Spinner's width part
like this?
<LinearLayout 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" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<EditText
android:layout_width="wrap_content"
android:layout_weight="75"
android:layout_height="wrap_content"
android:id="#+id/summoner_name"/>
<Spinner
android:layout_weight="1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/regions"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="#+id/search_button"/>
</LinearLayout>
</LinearLayout>
I'm trying to put a TextView on top, another on bottom, and a ListView in between using the remaining space.
However, my ListView is taking all the space to the bottom, making the last TextView to not even show up. The only way I can make it show up is to give the ListView a fixed height, like 100dp.
My layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/id_task_list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title_task_list"
style="?android:attr/listSeparatorTextViewStyle" />
<ListView
android:id="#+id/id_task_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/id_task_list_title" />
<TextView
android:id="#+id/id_task_list_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/id_task_list_view"
android:text="OMG Test" />
</RelativeLayout>
Use LinearLayout as follows:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:id="#+id/id_task_list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title_task_list"
style="?android:attr/listSeparatorTextViewStyle" />
<ListView
android:id="#+id/id_task_list_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<TextView
android:id="#+id/id_task_list_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="OMG Test" />
</LinearLayout>
This should solve your issue by placing your ListView between the TextViews using both android:layout_above and android:layout_below :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/id_task_list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title_task_list"
style="?android:attr/listSeparatorTextViewStyle" />
<TextView
android:id="#+id/id_task_list_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="OMG Test" />
<ListView
android:id="#+id/id_task_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/id_task_list_test"
android:layout_below="#id/id_task_list_title"/>
</RelativeLayout>
It can be achieved one of the two ways
1) Using Linear Layout (Straight forward)
2) Using Relative Layout with referencing the view position with respected to the other views.
In your case
1) Change Relative to LinearLayout and work will be done.
2)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/id_task_list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/title_task_list"
style="?android:attr/listSeparatorTextViewStyle" />
<ListView
android:layout_below="#+id/id_task_list_title"
android:id="#+id/id_task_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/id_task_list_title" />
<TextView
android:layout_below="#+id/id_task_list_view"
android:id="#+id/id_task_list_test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/id_task_list_view"
android:text="OMG Test" />
</RelativeLayout>
This can be done through coding by getting the height of screen and alloting layout param width to list view like this
height of list view=screen height-(height of textView1+Height of textView2).
Instead of Using RelativeLayout , use LinearLayout with Orientation Vertical.
I think it solves your problem
Thank you
I today added a scrollview to my app. I wanted something like google now cards. It worked, but I want it to be fullscreen, but on the bottom. On the bottom i got a EditText and a Button and i want the scrollview to stop there, so that they are both visible. How can i do that? :s
That's my activity:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/chat_layout"
android:icon="#drawable/ic_linkrholoorange"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".Chat"
android:text = "Now">
<ScrollView 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:fillViewport="true" >
<com.linkr.chat.NowLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#e3e3e3"
android:orientation="vertical">
<TextView
android:id="#+id/card"
style="#style/nowCardStyle"
android:layout_width="match_parent"
android:layout_height="100dp"
tools:context=".Chat"
android:layout_alignTop="#+id/linearLayout"
android:layout_alignLeft="#+id/linearLayout"/>
</com.linkr.chat.NowLayout>
</ScrollView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="10dp"
android:id="#+id/linearLayout">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:ems="10"
android:id="#+id/chatTextArea"
android:layout_alignTop="#+id/sendButton"
android:layout_toLeftOf="#+id/sendButton"
android:layout_alignBottom="#+id/sendButton"
android:layout_alignLeft="#+id/scrollView"
android:enabled="false"
android:focusable="false"
android:hint="What's on your mind..."
android:visibility="visible"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/sendButton"
android:gravity="bottom"
android:background="#drawable/social_send_now"
android:onClick="sendMethod"
android:layout_alignBottom="#+id/scrollView"
android:layout_alignRight="#+id/scrollView"/>
</LinearLayout>
</RelativeLayout>
<!-- The navigation drawer -->
<!--<ImageView
android:id="#+id/drawerimage"
android:layout_width="320dp"
android:layout_height="100dp"
android:layout_gravity="start"
android:background="#drawable/desert"
android:choiceMode="singleChoice"></ImageView>-->
<ListView
android:id="#+id/drawer"
android:layout_width="320dp"
android:layout_height="match_parent"
android:background="#F3F3F4"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:hint="What's on your mind?"
android:divider="#android:color/darker_gray"
android:dividerHeight="1dp" ></ListView>
</android.support.v4.widget.DrawerLayout>
I hope you can help me
Thanks a lot!
You haven't said what is happening so its hard to say what the problem is. However, yo make this the way it sounds you want I would suggest adding the property
android:layout_alignParentBottom="true"
to your LineareLayout with the EditText and the Button. See if that works. Something like
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="10dp"
android:id="#+id/linearLayout"
android:layout_alignParentBottom="true"> <!-- Add this line here -->
The parent of your EditText and Button is a LinearLayout but they have properties such as these
android:layout_alignTop="#+id/sendButton"
android:layout_toLeftOf="#+id/sendButton"
android:layout_alignBottom="#+id/sendButton"
android:layout_alignLeft="#+id/scrollView"
but these are properties of a RelativeLayout so they won't have any effect, at least not any wanted effect, on Views whos parent is a LinearLayout.
See The Docs for the properties that each ViewGroup has.
In my app I've got an activity with an EditText view on top of a ListView. The simple problem I'm having is that the topmost element of the list is "underneath" the EditText view.
I'm not very experienced in Android and so I have no idea how to fix this!
My xml looks like this
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".AcceptDeliveriesMainActivity" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<!-- Editext for Search -->
<EditText android:id="#+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/search_field_text"
android:inputType="textVisiblePassword"/>
</LinearLayout>
<!-- List View -->
<ListView
android:id="#+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
as long as your linearlayout just contains one element, so you can delete it.
you have to use android:layout_below="#+id/inputSearch" in your listview
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".AcceptDeliveriesMainActivity" >
<EditText
android:id="#+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textVisiblePassword" />
<!-- List View -->
<ListView
android:id="#+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/inputSearch" />
</RelativeLayout>
If you don't want to remove the linearlayout
you can use this:
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".AcceptDeliveriesMainActivity" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/llID"
android:orientation="horizontal" >
<!-- Editext for Search -->
<EditText
android:id="#+id/inputSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textVisiblePassword" />
</LinearLayout>
<!-- List View -->
<ListView
android:id="#+id/list_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/llID" />
</RelativeLayout>
In the previous code, I just gave an ID to the linearlayout and made the listview below it
You should replace your parent RelativeLayout with a LinearLayout.Or place the child views in relation to each other like android:layout_below which will then align children in relation to each other. Else each child will align to top left of the parent.
Tell your 2nd ListView to layout:below your LinearLayout.