I am using a gridview to display a collection of items in the form of an image with a textview beneath them for their title.
The final item of collection of items is unique in the fact that it only has an image, no textview (this might be relevant).
At the moment I am finding that as soon as a row is created that has a normal item and an image only item in it, the textview is cutoff.
I have tried setting the min height and height of the items but it doesn't seem to affect the grid at all.
Grid:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="#drawable/Background"
android:id="#+id/root_layout"
android:padding="10dip"
android:layout_height="match_parent">
<GridView
android:id="#+id/connection_grid"
android:listSelector="#android:color/transparent"
android:horizontalSpacing="25dip"
android:stretchMode="columnWidth"
android:verticalSpacing="25dip"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Grid Item:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="300dp">
<FrameLayout
android:id="#+id/screencap_layout"
android:layout_height="wrap_content"
android:background="#drawable/RowBorderBackground"
android:layout_width="wrap_content"
android:padding="1dip"
android:layout_centerHorizontal="true">
<ImageView
android:id="#+id/connection_icon"
android:layout_width="200dip"
android:layout_height="147dip"
android:background="#drawable/grid_view_selector"
android:scaleType="centerCrop" />
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/devicetype_layout"
android:background="#drawable/RowBorderBackground"
android:layout_gravity="right|bottom"
android:layout_marginBottom="-2dip"
android:layout_marginRight="-2dip"
android:padding="2dip">
<TextView
android:text="NA"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/device_type" />
</RelativeLayout>
</FrameLayout>
<TextView
android:id="#+id/connection_name"
android:text="Machine 1"
android:gravity="center"
android:textSize="18dip"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
Set some paddingBottom to gridview gridview class.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="#drawable/Background"
android:id="#+id/root_layout"
android:layout_height="match_parent">
<GridView
android:id="#+id/connection_grid"
android:listSelector="#android:color/transparent"
android:horizontalSpacing="25dip"
android:stretchMode="columnWidth"
android:verticalSpacing="25dip"
android:paddingBottom="20dip"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Related
So, I have the following .xml:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.scopesystems.cityalert.ui.Despre"
tools:showIn="#layout/app_bar_despre"
android:background="#drawable/toolbar_incercare">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="#+id/linear_parent">
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.1" />
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="2.8" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--General-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/sectionHeader"
android:text="#string/general"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/despre_general"/>
<!--Evaluti-ne-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/sectionHeader"
android:text="#string/evaluatine"
/>
<!--Confidentialitate si licente-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/sectionHeader"
android:text="#string/confidentialitate"
/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/despre_politici"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.1" />
</LinearLayout>
</ScrollView>
The issue is that the last ListView is on only 1 row, and it has to be scrolled to display all the items in the list. I tried to add to the linear_parent a height of match_parent but it wont let me, it says that I should use instead wrapcontent. How can i change the layout to display the items on all the screen, not just half?
In this case, On the ScrollView use android:fillViewport="true" and for child of ScrollView android:height="wrap_content".
I am struggling with my Android Layout.
I want to create a Linear Layout which contains a Button at the Top, next a List View and when all elements of the list view are displayed I want to show a Fragment which displays Google Maps.
This is my Layout xml file. In that case you can only see the Fragment and the Button but not the listview
<?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:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:orientation="vertical"
tools:context="de.mypackage.MyActivity">
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="0"
android:id="#+id/button_back"
android:text="#string/back"
/>
<ListView
android:id="#+id/list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1"/>
/>
<fragment
android:id="#+id/fragement"
android:name="de.mpackage.MapsFragment"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="0"
tools:layout="#layout/fragment_maps"/>
</LinearLayout>
Any Idea how I can realize my layout?
Try this code
<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="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:weightSum="1"
android:paddingRight="10dp">
<Button
android:id="#+id/button_back"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/back" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5" />
<fragment
android:id="#+id/fragement"
android:name="com.yougotag.supplierfieldagent.fragments.AboutFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
tools:layout="#layout/fragment_about_app" />
</LinearLayout>
this will set both in half screen you can change ration of weights in layout.
Advice :
Declare your root layout as RelativeLayout
RelativeLayout is a view group that displays child views in relative
positions. The position of each view can be specified as relative to
sibling elements .
Then use android:layout_below
Positions the top edge of this view below the given anchor view ID.
Accommodates top margin of this view and bottom margin of anchor view.
<fragment
android:id="#+id/fragement"
android:name="de.mpackage.MapsFragment"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_below="#+id/birth"
tools:layout="#layout/list"/>
Try this code
<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="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<Button
android:id="#+id/button_back"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/back" />
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<fragment
android:id="#+id/fragement"
android:name="com.yougotag.supplierfieldagent.fragments.AboutFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="#layout/fragment_about_app" />
</LinearLayout>
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:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp"
tools:context="de.mypackage.MyActivity">
<Button
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="0"
android:id="#+id/button_back"
android:text="#string/back"
/>
<ListView
android:id="#+id/list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_below="#+id/button_back"/>
/>
<fragment
android:id="#+id/fragement"
android:name="de.mpackage.MapsFragment"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="0"
android:layout_below="#+id/list"
tools:layout="#layout/fragment_maps"/>
</RelativeLayout>
I found a solution hope it helps.
In my ListView for the height instead of using 0dp I used wrap_content and adds layout_weight=1 for my Fragment
<LinearLayout
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"
android:background="#EFEFEF"
android:orientation="vertical">
<Button
android:id="#+id/button_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<ListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:divider="#null"/>
<fragment
android:name="de.mpackage.MapsFragment"
android:id="#+id/fragement"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="5dp"
android:layout_weight="1"
/>
</LinearLayout>
I have a GridView in a vertical LinearLayout, that I want to have take up all remaining vertical space. The grid will always have 5 columns and 7 rows. The grid items are just a TextView. I want the grid items to expand proportionally (so that each item is one fifth of the width and one seventh of the height) to fill remaining space on any device. I tried setting layout weights, but that didn't do anything.
How can I make it fill the space?
Here's my activity:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<TextView
android:text="#string/zero"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tv0"
android:gravity="end"
android:textAppearance="#style/TextAppearance.AppCompat.Large"
android:paddingEnd="8dp"
android:paddingStart="8dp"
android:textColor="#e4e4e4"
android:background="#color/colorPrimaryDark"/>
<!-- A few more TextViews -->
<GridView
android:id="#+id/grid_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:horizontalSpacing="0dp"
android:verticalSpacing="0dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:numColumns="5"/>
</LinearLayout>
And here's the layout for the grid item:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="#color/colorPrimary"
android:paddingBottom="15dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"/>
</FrameLayout>
I didn't understand exacly what you meant by "proportionally", but to make the GridView "fill the space" in your example you don't need to set layout weights:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/text" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/text" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/text" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/text" />
<GridView
android:id="#+id/grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:horizontalSpacing="0dp"
android:numColumns="5"
android:stretchMode="columnWidth"
android:verticalSpacing="0dp" />
</LinearLayout>
Generates the layout below:
I want to see RecyclerView items when scrolling it from behind of top layout ( LinearLayout with top id).
I can see the scroll bar from behind but recyclerview item , no .
please help.
this is my xml layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#android:color/transparent">
<LinearLayout
android:background="#android:color/transparent"
android:alpha="0.25"
android:id="#+id/top"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:background="#80000000"
android:textColor="#color/material_blue_grey_950"
android:id="#+id/btn_ketabdonUpdate"
android:layout_width="0dp"
android:text="yyyyy"
android:layout_weight="1"
android:layout_height="match_parent" />
<android.support.v7.widget.AppCompatButton
android:background="#80000000"
android:textColor="#color/material_blue_grey_950"
android:id="#+id/btn_ketabdonFilter"
android:text="xxxxx"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/swipeRefreshLayout"
>
<android.support.v7.widget.RecyclerView
android:paddingTop="50dp"
android:scrollbars="vertical"
android:fadeScrollbars="true"
android:paddingRight="5dp"
android:verticalScrollbarPosition="left"
android:scrollbarStyle="outsideInset"
android:id="#+id/rv_fragment"
android:layout_height="match_parent"
android:layout_width="wrap_content"
/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
Hi in my application I am displaying image and text by using grid view for that i used frame layout inside linear layout.
Now i want above the list view i want to display some image.
can anyone please help me.
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<com.agilerise.hotel.SquareImageView
android:id="#+id/picture"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:paddingTop="50dp"
android:paddingBottom="50dp"
/>
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_gravity="bottom"
android:textColor="#android:color/black"
/>
</FrameLayout>
<GridView
android:id="#+id/buttom"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:numColumns="3"
android:layout_weight="1">
</GridView>
</LinearLayout>
add list view in your xml
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.68" >
</ListView>
and create item.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="#drawable/ic_avatar"
android:scaleType="centerCrop"/>
</LinearLayout>
Then you should use ArrayAdapter in your activity class to create your listview...