<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:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#drawable/location_edittext"
android:id="#+id/locationEditext"
android:textSize="15sp"
android:textColor="#999"
android:paddingLeft="15dp" />
<com.example.ravi_gupta.slider.ViewPagerCustomDuration
android:layout_width="wrap_content"
android:layout_height="0dp"
android:id="#+id/viewPager"
android:scrollbarStyle="outsideOverlay"
android:layout_weight="0.5">
</com.example.ravi_gupta.slider.ViewPagerCustomDuration>
<ListView
android:layout_weight="0.50"
android:layout_below="#+id/viewPager"
android:layout_marginTop="2dp"
android:layout_width="match_parent"
android:layout_height="45dp"
android:id="#+id/shopListview" />
This is my code in activity.main I, all I want is that when I scroll the listview it take all the space in the layout hiding viewpager and editext and when I scroll back it shows both of them, I don't know how this can be possible, Either I should use Relative layout or some Other method
You cannot simply depend on the layout. Modify your code and look at setVisibility method # setVisibility of View.
For example, if that method is set to GONE to EditText UI, then that UI is completely hidden as if it was never shown. And then of course, you should set it to VISIBLE when appropriate.
Related
I have a layout wich contains next views:
<android.support.v7.widget.RecyclerView
android:id="#+id/rvChat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/stickersContainer"
android:layout_alignParentTop="true" />
<ImageButton
android:id="#+id/ibChatSmile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="6"
android:background="?attr/selectableItemBackgroundBorderless"
android:paddingBottom="8dp"
app:srcCompat="#drawable/smile" />
<LinearLayout
android:id="#+id/stickersContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:visibility="visible">
<android.support.design.widget.TabLayout
android:id="#+id/tbStickers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/stickersPager"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/tbStickers"
android:visibility="gone" />
</LinearLayout>
stickersContainer - is layout which I want to show/hide. Recyclerview contains chat messages and ImageButton shows/hides
stickersContainer. As you see there are tabLayout and ViewPager in stickersContainer.
To ViewPager I load this fragment:
<FrameLayout 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"
tools:context="com.oopslab.outarguemechat.Fragments.Stickers.StickersContainerFragment">
<GridView
android:id="#+id/gvStickersContainer"
android:layout_width="match_parent"
android:layout_height="200dp"
android:numColumns="3" />
for hiding/showing layout I use setVisibility() function;
and it seems all works well until I called notifyDataSetChanged() for recyclerview.
when I press a hide button it hides layout but button and recyclerview stayed at their places.
I'm really confused with this situation. I tried to put layout to the fragent and add/remove it but nothing helps
Also I tried adapter.notifyItemInserted() instead of notifyDataSetChanged() but had the same result
As you might guess, I'm trying to create something like sticker layout(like in viber/telegram/skype, etc).
May be there is another way to make it.
Thanks in advance!
I was able to this somehow using RecyclerView. When I create a view for a specific item in my RecyclerView, the recyclerview item layout is matched to parent.
I am wondering if this is also possible using ScrollView?
Here's what I did so far:
ScrollView xml:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/scrollview_homescreen"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:id="#+id/linearlayout_homescreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/listitem_comic_menu"/>
<LinearLayout
android:id="#+id/linearlayout_comic_listings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
</ScrollView>
Content:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativelayout_homescreen"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imageview_menu_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:adjustViewBounds="true" />
<ImageView
android:id="#+id/imageview_menu_title_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/starwars_webtoon_home_1_logo"
android:scaleType="fitXY"
android:adjustViewBounds="true" />
<Button
android:id="#+id/button_start_reading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="#+id/button_menu"
android:layout_marginBottom="18dp"
android:text="#string/button_start_reading"
android:gravity="start"
android:drawableRight="#drawable/ic_keyboard_arrow_right_black_24dp"
android:drawableEnd="#drawable/ic_keyboard_arrow_right_black_24dp"
android:background="#drawable/button_bg"
android:textSize="18sp"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:layout_marginEnd="12dp"
android:layout_marginRight="12dp" />
<Button
android:id="#id/button_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="28dp"
android:text="#string/button_menu"
android:textSize="18sp"
android:textColor="#FFFFFF"
android:drawableLeft="#drawable/ic_menu_white_24dp"
android:drawableStart="#drawable/ic_menu_white_24dp"
android:background="?android:attr/selectableItemBackground" />
</RelativeLayout>
So what am I trying to do? Basically this is for comic listing. The first item should be the homescreen, a couple of button here and there and the entire application logo. The next item should show the listings (I have 40 items of the same width and height) and a footer.
I need my homescreen to match the parent which is the screen. So when I scroll the topmost part, the first item (the first view, which is the homescreen) fills the entire devices screen.
I was able to to do this on RecyclerView and looks nice. I have encountered some of problems that plague me which I have to fix extensively to the point that I am hacking through the system and I realize RecyclerView is not really the best layout for this kind of case. I am currently deciding whether to switch to ScrollView and dynamically/statically add the comic items. But, the homescreen, which is the first View is not matching the screen device.
I would just like to ask if this possible at all to do in ScrollView?
Thanks!
Use weight attribute:
<LinearLayout
android:id="#+id/linearlayout_homescreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<include layout="#layout/listitem_comic_menu"/>
<LinearLayout
android:id="#+id/linearlayout_comic_listings"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
I am trying to scroll the listview inside one Linear Layout but it is not working as i want. I am attaching one image for the more explanation.
This is my Layout
<android.support.v7.widget.CardView
android:id="#+id/card"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:clickable="false"
app:cardBackgroundColor="#android:color/white"
app:cardElevation="2dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="false">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical">
<Button
android:id="#+id/findSelected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:background="#drawable/flat_selector_green"
android:text="Next"
android:textColor="#android:color/white" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.v7.widget.CardView>
Image explanation
I know it s not the good approach to use the listview but i have to do this with this way.
Just remove the ScrollView from your xml code, Because ListView have their own Scroll doesn't require ScrollView.Then code will work as you want. Second List will be shown after showing every item of first ListView.
According to android docmentation
You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.
First you user card view as top parent it seem you will use it as child of list view as I guess , if my guessing is correct this not wise to use two list view as child.
Second In any case you want use two listview in same view , its recommended to separate between them with view (TextView , ... etc).
the solution
1- remove scroll as it useless.
2- add weight to your list view as wrap content in your case mean whole view.
3- recommend add view to separate between list.
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/card"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:clickable="false"
app:cardBackgroundColor="#android:color/white"
app:cardElevation="2dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/wholeview"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="2">
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<!-- recommended to add view here -->
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/findSelected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center"
android:text="Next"
android:textColor="#android:color/white"
/>
</LinearLayout>
</RelativeLayout>
I have an activity with several entry fields. I has an action bar. When I move down, at a certain point, the action bar starts to move up, and if I enter some entry fields further down, the action bar disappears totally.
How do I ensure that the action bar is fixed at the top and does not disappear, even if there are many fields down the window?
...
<LinearLayout 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/activityHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal"
android:paddingLeft="3dp"
android:paddingRight="3dp">
<TextView
android:id="#+id/activityTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
</LinearLayout>
... other horizontal LinearLayout follow...
...
One solution is to use ScrollView as "root" layout, then only one direct dependent Layout (such as a LinearLayout) that will serve as container for all other necessary layouts and components needed to your activity.
...
Such as:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/activityHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal"
android:paddingLeft="3dp"
android:paddingRight="3dp">
<TextView
android:id="#+id/activityTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
</LinearLayout>
... all other necessary layouts here...
</LinearLayout>
You could use a Toolbar and place it into the linear layout as a sibling along with your scroll view. It will look something like this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/activityHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal"
android:paddingLeft="3dp"
android:paddingRight="3dp">
<TextView
android:id="#+id/activityTitleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
</LinearLayout>
... all other necessary layouts here...
</LinearLayout>
Make sure that android:orientation is set to "vertical"
I "Googled" the problem and could not find the same type of problem described, and no solution.
It is when I was viewing Udacity NanoDegree Lesson on Developing Android Apps that I saw the use of ScrollView. So the solution is to use a ScrollView as the root layout, then a single LinearLayout that will be the container of all other necessary layouts and views needed for your activity. ScrollView can only one dependent. See YouTube demo
do you mean your action bar is like this and you want to make it stable like the fourth picture?
you need to chandge the theme and make windowActionBarOverlay set to false
from
<item name="android:windowActionBarOverlay">true</item>
to
false
How to change the height of ExpandableListView when group is expanded/collapsed?
I want to change the height of ExpandableListView to fit the height of its content, so that the view will not scroll inside itself.
this is the layout for main activity.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="jp.foo.android.activity.FooActivity"
tools:ignore="MergeRootFrame" />
and this is a layout for the fragment of the main activity.
<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"
tools:context="jp.foo.android.fragment.FooFragment"
android:background="#color/category_bg">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:id="#+id/frameLayout">
<TextView
android:text="#string/subtitle_question_category"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/subtitle_category"
android:gravity="center_vertical|center_horizontal"
android:layout_gravity="center_horizontal|top"
android:textSize="20sp" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/frameLayout"
android:background="#drawable/category_list_bg_shape"
android:layout_marginTop="0dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:minHeight="300dp">
<LinearLayout
android:id="#+id/category_list_progressbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical"
android:visibility="gone">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/category_list"
android:transcriptMode="normal">
</ExpandableListView>
</FrameLayout>
</RelativeLayout>
Below is the actual layout.
ExpandableListView will scroll inside when it has too many contents.
I want to scroll whole screen. Not only scroll view, but with header.
I solved a similar issue putting everything into a Header. I was close to solving it the traditional ways (ie. nesting layouts, weights, ...) but I felt the solution was pretty dirty, requiring overriding methods such as onGroupClick etc... to disable the ExpandableListView's scroll, while the header thing was clean and worked flawlessly for me.
So if you want to try this approach, just put an ExpandableListView alone inside your fragment, and prepare the rest to be inserted as Header.
So in your fragment a full ExpandableListView:
<ExpandableListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/category_list"
android:transcriptMode="normal">
</ExpandableListView>
Then create the layout expandable_header.xml:
<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"
tools:context="jp.foo.android.fragment.FooFragment"
android:background="#color/category_bg">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:id="#+id/frameLayout">
<TextView
android:text="#string/subtitle_question_category"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/subtitle_category"
android:gravity="center_vertical|center_horizontal"
android:layout_gravity="center_horizontal|top"
android:textSize="20sp" />
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/frameLayout"
android:background="#drawable/category_list_bg_shape"
android:layout_marginTop="0dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:minHeight="300dp">
<LinearLayout
android:id="#+id/category_list_progressbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical"
android:visibility="gone">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</RelativeLayout>
And then inflate the header into the ExpandableListView:
.
.
.
View view = View.inflate(context, R.layout.expandable_header, null);
expandableList.addHeaderView(view, null, false);
.
.
.
This way the header will scroll together with the ExpandableListView, as it's inside it.
BTW, your layout has redundant elements, for example the FrameLayout that contains only a TextView. You can use only the TextView. Also the LinearLayout with the ProgressBar, if you are not using an opaque background, you could put the ProgressBar alone. The less ViewGroups you use the better the layout will perform!