Multiple GridViews with IMAGES, inside a ScrollView - android

Selection Activity
Selection Activity
What i which to accomplish by using IMAGES inside a GridView is to allow the user to decide from ALL MY options which ones is he willing to do, the challenge throughout the whole process of creating this activity, has been trying to make it possible to fit everything in one screen with a ScrollView while maintaining the pictures.
In the images when the user has selected something it will be more opague (in the pictures is complete black).
I have been searching all over the place, and this is what has helped me so far:
- ScrollView Layout does not fill the whole screen
- Gridview height gets cut
If any of you know a work around or other viable alternative, please dont hesitate to indulge me. I can also post my activity class, but i feel is redundant.
<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">
<RelativeLayout
android:id="#+id/activity_woman_activities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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="tech.destinum.baewatch.WomanActivities">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/titleIndoorActivities"
android:text="Indoor Activities"
android:gravity="center"
android:textSize="24sp"/>
<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/gridviewWomanActivities"
android:layout_below="#id/titleIndoorActivities"
android:numColumns="2"
android:horizontalSpacing="8dp"
android:verticalSpacing="8dp"
android:gravity="center"
android:stretchMode="columnWidth"
android:layout_marginTop="10dp"
android:minHeight="20dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/titleOutdoorActivities"
android:text="Outdoor Activities"
android:gravity="center"
android:textSize="24sp"
android:layout_below="#+id/gridviewWomanActivities"
android:layout_alignParentStart="true"
android:layout_marginTop="18dp"/>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/gridviewWomanActivities2"
android:numColumns="2"
android:horizontalSpacing="8dp"
android:verticalSpacing="8dp"
android:gravity="center"
android:stretchMode="columnWidth"
android:minHeight="20dp"
android:layout_below="#+id/titleOutdoorActivities"
android:layout_alignParentStart="true"
android:layout_marginTop="10dp"/>
<Button
android:text="be spontaneous!"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/gridviewWomanActivities2"
android:layout_centerHorizontal="true"
android:id="#+id/button5"
android:layout_marginTop="10dp"/>
</RelativeLayout>
</ScrollView>

Related

Image does not touch the edges, Android [duplicate]

I am creating an Android app which has a main RelativeLayout and some LinearLayout within it.
Now i have this problem. When dragging items to the editor, e.g. a LinearLayout, it doesn't fit to the full width of the screen. How can I make this possible? This is my XML:
<RelativeLayout 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"
android:gravity="fill"
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" >
<LinearLayout
android:id="#+id/itemDetailLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/itemImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="40dp"
android:minWidth="40dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/itemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:fillViewport="true" >
<TextView
android:id="#+id/itemRecentHigh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recent High" />
<TextView
android:id="#+id/itemRecentLow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recent Low" />
<TextView
android:id="#+id/itemAverage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Average" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/listViewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/itemDetailLayout"
android:layout_marginTop="10dp"
android:fillViewport="true"
android:gravity="fill_horizontal"
android:orientation="vertical" >
<ListView
android:id="#+id/searchListView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
</ListView>
</LinearLayout>
Added a screenshot for more info. Added blue background to have some contrast.
Replace this:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
With
android:layout_width="match_parent"
android:layout_height="wrap_content"
into your LinearLayout or Remove all the Padding from main RelativeLayout
Removing padding makes the linear layout fit the entire screen of the device
The space between the blue part and the "end of the screen". On the sides and above the part where the back button and home button are.
Remove the padding from the root RelativeLayout.
Try
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical>
// Other views within the linear layout
</LinearLayout>
I suppose you are using Eclipse. Personally, I hate the Graphical Editor of Eclipse and I usually write the XML code directly because working with the editor is a real pain
Don't use fill_parent as it is deprecated.
Instead to your RelativeLayout set
android:layout_width="fill_parent"
android:layout_height="fill_parent"
Then, to the list view that you want to fill the rest of the screen, you can set this tags
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
By doing so, you are telling the XML that you want your ListView to do what fill_parent used to do in previous versions of Android.
Kind regards!
you should try something like the following :
<LinearLayout
android:id="#+id/itemDetailLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
...
</LinearLayout>
what i mean you should do this :
android:layout_width="fill_parent"
for every LinearLayout that you want its width to fill_parent .
FILL_PARENT means that the view wants to be as big as its parent as mentioned in the documentation .
and please give me some feedback
Hope That Helps .

Buttons gone after added swiperefreshlayout

I have a layout with listview and two buttons side by side at the bottom of the listview. Everything work fine until I have added the swiperefreshlayout for my listview.
My codes are as below.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFF"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/search_bar"
android:background="#color/colorPrimaryDark"
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
>
<EditText
android:id="#+id/keyword_editText"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:background="#drawable/search_edit_text"
android:hint="Keyword"
android:textColorHint="#color/list_item_title"
android:textColor="#000"
android:layout_centerVertical="true"
android:maxLines="1"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView_layout"
android:orientation="vertical"
android:layout_below="#+id/search_bar"
>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/refresh"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:id="#+id/RsListView"
android:dividerHeight="1dp"
android:divider="#D3D3D3"/>
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
android:id="#+id/test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="#+id/req_history_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Request History"
android:layout_weight="1"
android:background="#drawable/request_history_button"
android:textColor="#drawable/button_text_color"
/>
<Button
android:id="#+id/apprv_history_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Approval History"
android:layout_weight="1"
android:background="#drawable/approval_history_button"
android:textColor="#drawable/button_text_color"
/>
</LinearLayout>
</LinearLayout>
Sorry for dumping my codes here as I can't figure out any other way for you guys to understand my code.
Please help
Inside LinearLayout usually all children have even dimension according to orientation. However, when you would like one child to take a little amount of place and another to fill the rest, you might be interested in layout_weight parameter. If the child that should fill the space gets android:layout_weight="1" it will fill the space making a place for other views.
In order to see the buttons add android:layout_weight="1" to SwipeRefreshLayout and set android:layout_height="0dp". That will make your buttons visible.

Cannot get ScrollView to work in app

My app has two sections, stuff to do for today, and for upcoming days.
I am able to hide/show these by pressing on the corresponding button but when I open both, there can be too much info and I can only scroll the listview for the upcoming days and not the entire screen.
I did some searching and I kept seeing ScrollView pop up but I can't get that to work, it crashes my app.
Here is my XML file
<?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="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="eu.agp_it.agpmobilemover.OverviewActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1.0"
android:gravity="center"
android:id="#+id/layout_button_today">
<Button
android:id="#+id/overview_button_today"
android:layout_height="wrap_content"
android:layout_weight="0.95"
android:layout_width="0dp"
android:textSize="20sp"
android:text="#string/overview_today"
android:gravity="center"
android:layout_marginTop="5px"
android:layout_marginBottom="5px"
android:background="#drawable/custom_buttonoverview"
android:onClick="buttonTodayOnClick"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_listview_today"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layout_button_today">
<ListView
android:id="#+id/listviewtoday"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp"
android:visibility="visible"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_button_upcoming"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1.0"
android:gravity="center"
android:layout_below="#id/layout_listview_today">
<Button
android:id="#+id/overview_button_upcoming"
android:layout_height="wrap_content"
android:layout_weight="0.95"
android:layout_width="0dip"
android:textSize="20sp"
android:text="#string/overview_upcoming"
android:background="#drawable/custom_buttonoverview"
android:gravity="center"
android:layout_marginTop="5px"
android:layout_marginBottom="5px"
android:onClick="buttonUpcomingOnClick"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_listview_upcoming"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layout_button_upcoming">
<ListView
android:id="#+id/listviewupcoming"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp"
android:visibility="gone"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
You probably don't need the ScrollView at all. The ListViews already do the scrolling for you. Nesting scrolling views isn't recommended.
Try taking out the ScrollView. Each LinearLayout could take up half the screen, or whatever amount you'd like. You could also use an ExpandableListView which would allow you to expand and collapse the assignments for today and upcoming days based on their header (Today, Upcoming). This way you would only need one ListView. So it would be easier to maintain.

Button completely disappears when placed below gridview despite numerous configurations

I have a view in which i'd like a button to be placed below a grid view and fill up the remaining space. The view is a relative layout, and no matter what attributes I give it, if I some how relate the button to the grid view, it disappears. It only appears if I place it in the relative view with it aligned parent bottom, but then it doesn't stretch. The solution I thought would be most likely, though it didn't work either, was to place the button in the relative view, alignParentBottom=True and then layout_below="id/gridview" (all that is psuedo code). This is my code right now:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/pin_fragment_background"
tools:context="com.lab125.viva_app.MainActivity$PlaceholderFragment" >
<TextView
android:id="#+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/audioPIN_marquee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="15dp"
android:paddingBottom="30dip"
android:gravity="center"
android:textSize="15sp"
android:textStyle="bold"
/>
<LinearLayout
android:id="#+id/keypad_wrapper"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_below="#id/audioPIN_marquee">
<GridView
android:id="#+id/keypad"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="5dip"
android:verticalSpacing="5dip"
android:numColumns="3"
android:stretchMode="columnWidth" />
<Button
android:id="#+id/start_ver_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:text="#string/Start_Ver_Button"
android:background="#drawable/button_style" />
</LinearLayout>
<Button
android:id="#+id/audio_playback_btn"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/keypad_wrapper"
android:text="play"
android:textSize="15sp">
</Button>
</RelativeLayout>
Again, with this code, the button does not show at all.
Edit: #Dave's suggestion was correct, and I could see the button after setting the orientation to vertical. However, the only reason I had placed the gridView in a linear layout in the first place was in attempt to just not have the button disappear when having its android:layout_below property to the gridView (by setting its android:layout_below to something else). The more accurate fix for what I wanted to do however, was to not have the gridView's width and height set to match_parent, which was the root cause behind why the button was disappearing. So, i set the gridView's height to wrap content, but that caused the grid to shrink to the point where each grid element's content was no longer visible. I found that the cause of that was => I was programmatically setting the width and height of the gridview to wrap its content, and then the width and height of the components inside by the width and height of the parent view. Realized that was quite cyclical which may be why the gridview was shrinking when I set it to wrap content. I then set the width and height of the grid Elements based on the dimensions of the screen, which fixed the size of the gridView. So everything pretty much works now.
Here is my new layout, if anyone is interested.
<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:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/pin_fragment_background"
tools:context="com.lab125.viva_app.MainActivity$PlaceholderFragment" >
<TextView
android:id="#+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/audioPIN_marquee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginBottom="20dp"
android:paddingTop="15dp"
android:gravity="center"
android:textSize="15sp"
android:textStyle="bold"
/>
<GridView
android:id="#+id/keypad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/audioPIN_marquee"
android:layout_marginTop="10dp"
android:layout_marginBottom="20dp"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="5dip"
android:verticalSpacing="5dip"
android:numColumns="3"
android:stretchMode="columnWidth" />
<Button
android:id="#+id/start_ver_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/keypad"
android:layout_alignParentBottom="true"
android:layout_marginTop="20dp"
android:textSize="15sp"
android:textStyle="bold"
android:text="#string/Start_Ver_Button"
android:background="#drawable/button_style" />
<!--
<Button
android:id="#+id/audio_playback_btn"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/keypad_wrapper"
android:text="play"
android:textSize="15sp">
</Button> -->
</RelativeLayout>
start_ver_btn won't show because the gridview has match_parent for both width and height, judging by your layout_width and heights, I think you want to set the LinearLayout's orientation to vertical.

Reduce spacing GridView

I'm try to create a GridView where the values are as close as possible to each other.
Now the content is spread out all over the screen.
How can I reduce the spacing between the cells of the GridView?
Using the setVerticalSpacing() method didn't work.
<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: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=".LevelSpelen" >
<GridView
android:id="#+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignLeft="#+id/textView1">
</GridView>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/gridView1"
android:layout_marginLeft="18dp"
android:text="" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="78dp"
android:layout_toRightOf="#+id/textView1"
android:text="Button" />
</RelativeLayout>
Any suggestions?
The spacing is defined in 2 ways: the spacing between cells, and the spacing within a cell
In your GridView definitions add
android:verticalSpacing="8dp"
android:horizontalSpacing="8dp"
or smaller and add android:numColumns="auto_fit" to make sure that you can fit as many items as possible in each row.
In the GridView Item layout, make sure that you make the cell as small or as big as you want

Categories

Resources