I have one fragment but its not vertically scrolling . My XML code is
<?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="fill_parent"
android:orientation="vertical"
android:background="#E6E6E6">
<!-- Top Sliding Banners -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="220dip" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom|left"
android:padding="10dip"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="Trending"
android:textColor="#000"
android:textSize="20sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textview"
android:scrollbars="none" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/popular_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="Popular"
android:textColor="#000"
android:textSize="20sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/popular_recycler_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/popular_textview"
android:scrollbars="none" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="#+id/featured_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="left"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:text="Featured"
android:textColor="#000"
android:textSize="20sp" />
<android.support.v7.widget.RecyclerView
android:id="#+id/featured_recycler_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/featured_textview"
android:scrollbars="none" />
</LinearLayout>
I have tried all solution of stackoverflow.My code have three recyclerview and they work fine .Only problem is than page is not vertically scrollable.
try using NestedScrollView as parent tag for this layout.
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
remember to keep only one direct child for nestedScroll view.
Related
I have a list view design for a recipes app. Each item consists of a image, title, description and number of calories. My problem is that it doesnt fill the entire screen, but instead it gives a scrollbar on the right.
How can I make it fill the screen?
Also, is there a better way of showing the list items without using tables?
list.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadingEdgeLength="0dp"
android:fillViewport="true"
android:overScrollMode="never"
android:scrollbars="none">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/listViewRecipes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp"
android:padding="10dp"></ListView>
</RelativeLayout>
</ScrollView>
</FrameLayout>
list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="horizontal"
android:padding="8dp"
android:fadingEdgeLength="0dp"
android:fillViewport="true"
android:overScrollMode="never"
android:scrollbars="none">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow
android:id="#+id/tableRow1">
<!-- Image -->
<ImageView
android:id="#+id/listViewRecipeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:overScrollMode="never"
app:srcCompat="#drawable/img_pixel" />
<!-- //Image -->
<!-- Title, Introduction -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="6dp"
android:fadingEdgeLength="0dp"
android:fillViewport="true"
android:overScrollMode="never"
android:scrollbars="none">
<TextView
android:id="#+id/listViewRecipeTitle"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/colorBlack"/>
<TextView
android:id="#+id/listViewRecipeIntroduction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/colorBlack"
android:text="Introduction"/>
</LinearLayout>
<!-- //Title, Introduction -->
<!-- Numbers -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginTop="6dp">
<TableRow>
<TextView
android:id="#+id/textViewServingCalories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/colorDarkGray"
android:text="xx" />
<TextView
android:id="#+id/textViewServingCaloriesKcal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/colorDarkGray"
android:layout_marginLeft="6dp"
android:text="#string/kcal_lowercase" />
</TableRow>
</TableLayout>
<TextView
android:id="#+id/textViewServingCaloriesKcalPerServing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/colorDarkGray"
android:text="#string/per_serving_lowercase" />
</LinearLayout>
<!-- //Numbers -->
</TableRow>
</TableLayout>
</LinearLayout>
This is a modify version of your code. You need to remove the outer scrollView since ListView is scrollable
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listViewRecipes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp"
android:padding="10dp">
</ListView>
</FrameLayout>
I have also remove the table layout and replace it with LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="3">
<ImageView
android:id="#+id/listViewRecipeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:overScrollMode="never"
app:srcCompat="#drawable/add" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:orientation="vertical">
<TextView
android:id="#+id/listViewRecipeTitle"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/colorBlack"/>
<TextView
android:id="#+id/listViewRecipeIntroduction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/colorBlack"
android:text="Introduction"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="8dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:orientation="horizontal">
<TextView
android:id="#+id/textViewServingCalories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/colorPrimary"
android:text="xx" />
<TextView
android:id="#+id/textViewServingCaloriesKcal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/colorPrimary"
android:layout_marginLeft="6dp"
android:text="Carolies" />
</LinearLayout>
<TextView
android:id="#+id/textViewServingCaloriesKcalPerServing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/colorPrimary"
android:text="Per Server" />
</LinearLayout>
Listview contains an inner scrollview. Just remove the scrollview.
either use that RelativeLayout or just the Listview on your frame. And match parent it.
I have one outer ScrollView in which there is one RecyclerView and three tabs. Every tab has a fragment and that fragment loads in corresponding tab using ViewPager but outer ScrollView does not scroll my layout. I used nested ScrollView but it also does not scroll. Maybe I did something wrong. Does any one have a suggestion? Please share with me.
Here is my xml code structure
<?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="match_parent"
android:layout_height="wrap_content"
android:id="#+id/parent_scroll"
android:layout_weight="1"
android:background="#color/business_price_bg"
android:focusableInTouchMode="false">
<RelativeLayout
android:id="#+id/business_detail_main_rl"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/activity_main_search_top_main_ll"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_main_search_top_main_ll_height"
android:background="#color/location_setting_bottom_button_color"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>
<RelativeLayout
android:id="#+id/business_detail_activity_business_slider_main_rl"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/activity_main_search_top_main_ll">
<android.support.v7.widget.RecyclerView
android:id="#+id/business_detail_activity_slider_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</RelativeLayout>
<TextView
android:id="#+id/business_detail_activity_business_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_slider_main_rl"
android:layout_margin="10dp"
android:text=""
android:textColor="#android:color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/business_detail_activity_business_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_title"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text=""
android:textSize="13sp" />
<android.support.design.widget.TabLayout
android:id="#+id/business_detail_activity_tabslayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_description"
android:background="#android:color/transparent"
app:tabIndicatorColor="#color/pencilin_orange_color"
app:tabIndicatorHeight="5dp"
app:tabTextAppearance="#style/MyTabLayoutTextAppearance" />
<android.support.v4.view.ViewPager
android:id="#+id/business_detail_activity_viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/business_detail_activity_tabslayout"
android:background="#android:color/white" />
</RelativeLayout>
</ScrollView>
You are going against the Android's UI Standards that's why you can never achieve your goals. Try to stick with Android UI Standards and make less complex UI.
I changed my screen Layout Structure and finally ScrollView is working
Here is solution:
<?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="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true">
<LinearLayout
android:id="#+id/business_detail_main_rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:id="#+id/activity_main_search_top_main_ll"
android:layout_width="match_parent"
android:layout_height="#dimen/activity_main_search_top_main_ll_height"
android:layout_weight="0."
android:background="#color/location_setting_bottom_button_color"
android:gravity="center"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.45"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/business_detail_activity_business_slider_main_rl"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/activity_main_search_top_main_ll">
<android.support.v7.widget.RecyclerView
android:id="#+id/business_detail_activity_slider_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:scrollbars="vertical" />
</RelativeLayout>
<TextView
android:id="#+id/business_detail_activity_business_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_slider_main_rl"
android:layout_margin="10dp"
android:text=""
android:textColor="#android:color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/business_detail_activity_business_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/business_detail_activity_business_title"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:text=""
android:textSize="13sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="1">
<Button
android:id="#+id/business_preview_screen_services_btn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.88"
android:background="#android:color/transparent"
android:text="#string/business_preview_screen_services_btn_str"
android:textAllCaps="false" />
<View
android:id="#+id/business_preview_screen_service_btn_seperator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.12"
android:background="#color/location_setting_bottom_button_color" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="1">
<Button
android:id="#+id/business_preview_screen_about_btn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.88"
android:background="#android:color/transparent"
android:text="#string/business_preview_screen_services_btn_about_btn_str"
android:textAllCaps="false" />
<View
android:id="#+id/business_preview_screen_about_btn_seperator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.13"
android:background="#color/light_gray_section_cell_seperator" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:weightSum="1">
<Button
android:id="#+id/business_preview_screen_staff_btn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.88"
android:background="#android:color/transparent"
android:text="#string/business_preview_screen_services_btn_staff_btn_str"
android:textAllCaps="false" />
<View
android:id="#+id/business_preview_screen_staff_btn_seperator"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.13"
android:background="#color/light_gray_section_cell_seperator" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:orientation="vertical">
<FrameLayout
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
I am getting this error java.lang.IllegalArgumentException: DrawerLayout must be measured with MeasureSpec.EXACTLY.
I need to ask why i need to give a specific width and height while using scroll view?
This is my xml :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="#+id/lin_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="#+id/iv_professonal_detail_info"
android:tag="image_tag"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/tv_name_detail_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"/>
<TextView
android:id="#+id/tv_designation_detail_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="#+id/tv_experience_detail_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_marginTop="10dp"
android:text="Specialization: "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="#+id/list_specialization"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_marginTop="10dp"
android:text="Education:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="#+id/list_education"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_marginTop="10dp"
android:text="Experiences:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="#+id/list_experience"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="horizontal"
/>
</LinearLayout>
<TextView
android:layout_marginTop="10dp"
android:id="#+id/tv_link"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View User Feedback"
android:textStyle="bold"
android:clickable="true"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
<!-- The navigation drawer -->
<ListView android:id="#+id/left_drawer"
android:layout_width="260dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#e5e5e5"
android:dividerHeight="1dp"
android:background="#android:color/black"
/>
</android.support.v4.widget.DrawerLayout>
</ScrollView>
I actually need a scroll view. Its working if i give a specific width and height but i donot want to use that because it may varies with phone dimensions. Please help
I am using Expandable GridView which doesn't scroll the whole content if grid items are changed dynamically.
Below is the xml code for main gridview
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="135dp">
<android.support.v4.view.ViewPager
android:id="#+id/pager1"
android:layout_width="match_parent"
android:layout_height="135dp"
android:layout_above="#+id/titles"
android:overScrollMode="never">
</android.support.v4.view.ViewPager>
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/titles"
style="#style/CustomCirclePageIndicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:padding="5dp" />
</RelativeLayout>
<fone.adipoli.shopping.ExpandableHeightGridView
android:id="#+id/gridView_shopping"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="center"
android:horizontalSpacing="0dp"
android:listSelector="#android:color/transparent"
android:numColumns="2"
android:stretchMode="columnWidth"
android:verticalSpacing="0dp" />
</LinearLayout>
Xml for each Grid item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardrow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
card_view:cardCornerRadius="3dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_gravity="center">
<ImageView
android:id="#+id/img_grid_row1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
/>
</LinearLayout>
<TextView
android:id="#+id/grid_row1_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=""
/>
<TextView
android:id="#+id/grid_row1_model"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall"
android:visibility="gone" />
<TextView
android:id="#+id/grid_row1_price_offr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall"
/>
<TextView
android:id="#+id/grid_row1_price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text=""
android:textSize="10sp"
/>
<TextView
android:id="#+id/grid_row1_product"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text=""
android:textSize="10sp"
android:visibility="gone"
/>
<TextView
android:id="#+id/buy_grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="2dp"
android:text="BUY"
android:padding="10dp"
android:gravity="center"
android:textColor="#color/white"
android:background="#color/blue"
android:textAppearance="? android:attr/textAppearanceSmall"/>
</LinearLayout>
</android.support.v7.widget.CardView>
I tried adding a view in the bottom after GridView ,but it doesn't work out.
Any help would be really thankfull.
Use android.support.v4.widget.NestedScrollView
or
ScrollView
Put your whole Grid items in NestedScrollView, or ScrollView seems to solve your problem.
I want to display a scroll view within ViewPager and action buttons below the ViewPager. So I set android:layout_weight="1" to ViewPager, but it was not displayed, and only action buttons was displayed.
The layout of ViewPager is following.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="1" />
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingBottom="10dp"
android:text="この記事の投稿者に" />
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="メールで問い合わせ" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="電話で問い合わせ" />
</LinearLayout>
</LinearLayout>
The layout within ViewPager is following.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent">
<TextView
android:id="#+id/title"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textSize="21sp" />
<ImageView
android:id="#+id/image"
android:layout_height="200dp"
android:layout_width="200dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_gravity="center" />
<TextView
android:id="#+id/price"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textSize="34sp"
android:textColor="#FF0000" />
<TextView
android:id="#+id/text"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textSize="21sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
When you are using weights with Layouts you need to use a height or width, depending on the orientation, of "0dp"
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="0.8" />
<LinearLayout
android:orientation="vertical"
android:layout_height="0dp"
android:layout_width="match_parent"
android:weight="0.2">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:paddingBottom="10dp"
android:text="この記事の投稿者に" />
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="メールで問い合わせ" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="電話で問い合わせ" />
</LinearLayout>
This should do the trick:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_weight="0" />
<LinearLayout
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1">
</LinearLayout>
</LinearLayout>