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.
Related
I am having this issue with a Listview, I have a PagerSlidingTabs with 4 tabs and a ViewPager, in the fist tab I have a fragment with a Listview.
The problem is that in the fist item of the list is a litle line that is not supposed to be there. I put the background of the Lisview Red so you can see this litle space that when I scroll is gone.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/adList"
android:visibility="visible">
<ListView
android:id="#+id/matchDetailsListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:clickable="false"
android:divider="#null"
android:dividerHeight="0dp"
android:background="#color/red" />
</RelativeLayout>
Here is the code of the tabs:
<com.astuetz.PagerSlidingTabStrip
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#color/transparent"
android:textColor="#color/white"
app:pstsDividerColor="#color/transparent"
app:pstsIndicatorColor="#color/bg_match_detail"
app:pstsIndicatorHeight="10dp"
app:pstsShouldExpand="true"
app:pstsTabBackground="#color/transparent"
app:pstsTabPaddingLeftRight="18dp"
app:pstsTextAllCaps="false"
app:pstsTriangleIndicator="true"
app:pstsUnderlineHeight="0dp" />
And here is what looks like when scroll the list (You can see that the space is gone) but when you are in the top of the list appears again:
Use this-:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/adList"
android:visibility="visible">
<ListView
android:id="#+id/matchDetailsListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:clickable="false"
android:divider="#null"
android:dividerHeight="0dp"
android:background="#color/transparent" />
</RelativeLayout>
Instead of-:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/adList"
android:visibility="visible">
<ListView
android:id="#+id/matchDetailsListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:clickable="false"
android:divider="#null"
android:dividerHeight="0dp"
android:background="#color/red" />
</RelativeLayout>
I want to have a static imageView inside a ScrollView. I need this image to stay in the same screen position even if the user scrolls. The problem is that the ScrollView accepts only one child element.
<ScrollView
android:id="#+id/scrollView"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
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=".MainActivity">
<ListView
android:id="#+id/finishedGameListView"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignTop="#+id/yourTurnListView"
android:layout_marginTop="200dp"/>
<TextView
android:id="#+id/theirTurnTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/yourTurnListView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:text="#string/their_turn"/>
<ImageView <!-- I want this to be fixed -->
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/ic_add_circle"
android:layout_below="#+id/theirTurnListView"
android:layout_alignRight="#+id/yourTurnListView"
android:layout_alignEnd="#+id/yourTurnListView"/>
</RelativeLayout>
Thanks
ScrollView can not be used in conjuction with ListView, ListView will not work properly.
If you really want to do this, try this code:
<FrameLayout>
<ScrollView/>
<ImageView/>
</FrameLayout>
I'm trying to make a screen scrollable with scroll view but my application keeps crashing.
What I've done is to replace RelativeLayout by ScrollView, but it doesn't work.
I need your help with this. Here is the code of the screen:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="0dp"
android:background="#drawable/background01"
tools:context=".MainActivity"
android:id="#+id/relativeLayout">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/id"
android:background="#drawable/lightcontainer"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:weightSum="1"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_marginBottom="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/mainTitle1"
android:id="#+id/textView"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:textSize="20sp"
android:textColor="#ffffff"
android:shadowColor="#000000"
android:shadowRadius="1.5"
android:shadowDx="2"
android:shadowDy="2"/>
</LinearLayout>
what you are trying to do is not an scrollable view it's just a relative layout. Try to put your code inside a ScrollView component, like this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<!-- PUT YOUR CODE HERE -->
</ScrollView>
Make sure you close all tags correctly as well (your relative layout is not closed).
<RelativeLayout>
Content
</RelativeLayout> <-- This closing tag is always necessary
I work with android, I want to draw design like this
There are two LinearLayuots ( blue and white ), I want add picture their borders, I have tryied to use minus margin but not work
Can Anybody help me?
You'd want something like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/firstRow"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#013032"
android:orientation="horizontal"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#ff3e7730"
android:layout_below="#+id/firstRow"/>
<ImageView
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:layout_width="140dp"
android:layout_height="140dp"/>
</RelativeLayout>
you can use a RelativeLayout for your layout's parent and then add two LinearLayout and one ImageView or Button. and set your Button (or ImageView,etc) to centerVertical and alignParentLeft and give some marginLeft to it!
<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="wrap_content"
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="com.example.neo.myapplication.MyActivity">
<LinearLayout
android:id="#+id/aboveLayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/darker_gray"
></LinearLayout>
<LinearLayout
android:layout_below="#+id/aboveLayout"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#android:color/holo_green_dark"></LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:src="#drawable/ic_launcher"/>
</RelativeLayout>
I have a LinearLayhout that contains a listView and below it an ImageButton.
When I add items to the list, the imageButton is moving lower and lower, which is what I want but when there are many elements in the list so that is the list is big enough to fill the screen, I can scroll down to the bottom of the list, but no further, meaning I can't see the imageButton anymore.
Code:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/add_interest_layout_root"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="#color/back"
android:layout_height="match_parent">
<ListView android:id="#android:id/list"
android:layout_width="match_parent"
android:divider="#drawable/downa"
android:footerDividersEnabled="false"
android:cacheColorHint="#android:color/transparent"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:layout_height="wrap_content">
</ListView>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/linearLayout2"
android:gravity="center">
<LinearLayout
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/LinearLayout16">
<ImageButton
android:src="#drawable/add"
android:id="#+id/btn_interest_more"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/transparent"></ImageButton>
<TextView
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:id="#+id/TextView08"
android:text="be more\nspecific"
android:gravity="center"></TextView>
</LinearLayout>
</LinearLayout>
What am I doing wrong? I want to be able to see the ImageButton even when I scroll down.
You should do something like this. Mind you this is a pseudo code so you better fill the correct attributes.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/add_interest_layout_root"
android:layout_width="match_parent"
android:background="#color/back" android:layout_height="match_parent">
<LinearLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:id="#+id/linearLayout2"
android:gravity="center" android:layout_alignParentBottom="true">
<!-- LinearLayout elements same as above -->
</LinearLayout>
<ListView android:id="#android:id/list"
android:layout_above="#+id/linearLayout2"
android:layout_width="match_parent"
android:divider="#drawable/downa"
android:footerDividersEnabled="false"
android:cacheColorHint="#android:color/transparent"
android:layout_gravity="center"
android:layout_marginTop="6dp" android:layout_height="match_parent">
</ListView>
</RelativeLayout>
Here is exactly the solution to your problem: http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/ which is solved by setting fillviewport on your listview.
Add this to your LinearLayout that holds the ImageButton
android:layout_alignParentBottom="true"
UPDATE:
Forget the above code. I misunderstand you. Sorry.
Do this instead: Add this layout as your root layout
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scroll"
android:scrollbars="none"
android:layout_weight="1">
<!-- Your code -->
</ScrollView>