I have an xml file that has the layout in ASCII form:
---------------
| ImageView
--------------
| TextView
--------------
| List...
--------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.some.app"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/MovieCover"
android:layout_width="100dip"
android:layout_height="100dip"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:padding="10dp"
android:id="#+id/TextHeader"
android:background="#000000">
</TextView>
<ListView android:id="#+id/ListView02" android:layout_height="wrap_content"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
I'm having a problem displaying the layout when my ImageView and TextView takes up more than 3/4 of the screen. How do I make ImageView and TextView scrollable with the ListView that is being displayed? At this point of time, only the ListView to be scrolled and I want the entire layout to be scrollable as though they are one page on its own.
How can I do that?
You can use <ScrollView> as your layout container
something along the line of
<ScrollView>
<LinearLayout>
// your layout here
</LinearLayout>
</ScrollView>
the reason why we need the LinearLayout inside is that ScrollView can only have one direct child
Butter to use two LinearLayout with layoutweight="1" and put ScrollView in one and listview in other
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- scroll view content -->
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout android:layout_weight="1"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<ListView android:id="#+id/ListView02" android:layout_height="wrap_content"
android:layout_width="fill_parent">
</ListView>
</LinearLayout>
ListView has addtoHeader and addtoFooter function. Make a separate layout and add it into header of ListView . In your case make a relative layout of imageview and textview and add it to the header of listview. The entire page will start scrolling.
How about putting the ImageView and TextView in a layout and putting this layout inside a ScrollView.?
Related
This is the image I want in my application:
I tried using listview inside a scrollview but the problem is that I am not able to stretch listview to its full size. Can anyone tell me how can I do this??
You can use your recyclerview as below example :
<android.support.v4.widget.NestedScrollView
android:id="#+id/nestedScroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_collapseMode="pin">
<!-- Some views-->
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_bubhub_comment_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
You can use below properties in recyclerview if you need both layout to scroll. Otherwise it would work as single scrolling view. These properties allows Recyclerview to scroll inside NestedScrollView
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
I have textview and listview in the RelativeLayout. How can I do scroll this textview when I scrolling listview? I want that textview does not to hang out from the top when I'm scrolling listview
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:padding="10dp"
android:paddingBottom="0dp"
android:id="#+id/info_presents_surveys"
android:text="#string/info_presents_surveys"
android:textColor="#color/empty_color"
android:background="#color/color_gray"/>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/info_presents_surveys">
<ListView
android:id="#+id/list_view_surveys"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#color/members_speakers.divider"
android:dividerHeight="1dp" />
</android.support.v4.widget.SwipeRefreshLayout>
The TextView is not within a scrolling component, it's within the parent layout RelativeLayout which does not scroll.
In order for it to scroll, you'll have to put it within a ScrollView (or similar scrolling component).
So it should be:
<ScrollView>
<RelativeLayout>
<TextView>
<SwipeRefreshLayout>
<ListView/>
</SwipeRefreshLayout>
</RelativeLayout>
</ScrollView>
I have a ExpandableListView inside of a fragment inside of a ViewPager.
The issue is that the group item is being cut in half horizontally, show below in the image.
I have the same exact code for the ExpandableListView elsewhere in the application, but inside of an activity, and it works fine?
XML layout for the group item:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:orientation="vertical"
>
<TextView
android:id="#+id/lbl_exercise_group"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:textSize="20dp"
android:textColor="#color/white"
android:background="#color/material_blue_500"
/>
</LinearLayout>
I think the layout_with from The TextView should be match_parent for the full size.
The issue was: in my ExpandableListView XML definition layout_width was set to wrap_content, it needed to be fill_parent
I changed:
<ExpandableListView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/exList_exercises"
android:clickable="true"
/>
to
<ExpandableListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/exList_exercises"
android:clickable="true"
/>
Supose I have a layout oriented vertically with one button in the top, a list view in the middle, and a button in the bottom:
------
BUTTON
LISTVIEW
LISTVIEW
LISTVIEW
------
I would like to make the whole layout scrollable, to be able to see the full list when scrolling down it:
------
LISTVIEW
LISTVIEW
LISTVIEW
BUTTON
------
I think I found it, here's a solution for you, without using ScrollView (which is actually not needed):
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button android:id="#+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
<ListView android:id="#android:id/list1"
android:layout_height="0dip"
android:layout_width="match_parent"
android:layout_weight="1" />
<ListView android:id="#android:id/list2"
android:layout_height="0dip"
android:layout_width="match_parent"
android:layout_weight="1" />
<ListView android:id="#android:id/list3"
android:layout_height="0dip"
android:layout_width="match_parent"
android:layout_weight="1" />
<Button android:id="#+id/btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
You can add a button to the header of a ListView and a button to the bottom of the ListView
Add a Button as header and a Button as footer to the ListView.
Write a custom Adapter for the ListView, return Button view at 0 and last position in getView().
I'm not really sure if you want to be able to scroll the buttons too, depending on that there are two ways which you can try. First where the button won't change their position while list view is scrolling. In this situation your xml should look 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" >
<Button
android:id="#+id/top_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<ListView
android:id="#+id/my_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/bottom_button"
android:layout_below="#+id/top_button" />
<Button
android:id="#+id/bottom_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
The second option is when you want these two buttons to scroll while list view is scrolling too. To achieve this you should add Buttons to your list view as header and footer :
mListView.addHeader(myFirstButton);
mListView.addFooter(mySecondButton);
And that should do the trick for you in both scenarios.
You should use android:layout_height="wrap_content"
I have a button inside of a LinearLayout that is oriented vertically. Not sure why the button doesn't show up?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical">
<com.commonsware.cwac.tlv.TouchListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tlv="http://schemas.android.com/apk/res/org.stocktwits.activity"
android:id="#android:id/list"
android:layout_width="fill_parent"
android:drawSelectorOnTop="false"
tlv:normal_height="64dip"
tlv:grabber="#+id/icon"
tlv:remove_mode="slideRight"
android:layout_height="wrap_content"/>
<Button android:text="Button" android:id="#+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
android:height="wrap_content" has no meaning for vertically-scrollable widgets like ListView. Use android:layout_weight with your LinearLayout or a RelativeLayout to achieve whatever look you are trying to achieve.
Try adding this to your LinearLayout:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
I'm guessing the layout is just not showing?