Gallery space at beginning and end - android

I got the following problem , i made a form with a gallery, the gallery instead of containing images contains items from one of my classes, everything inside each item of the gallery displays perfectly. I removed the space between images using:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Gallery android:id="#+id/galleryid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spacing="0dip"
android:padding="0dip"
android:layout_weight="1" />
the items of the gallery:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="75dip" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center_horizontal" android:background="#ffffff">
<TextView android:id="#+id/frame_number" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="-" android:textSize="12dip" android:textColor="#ffffff" android:background="#000000" android:gravity="center" />
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal" android:gravity="center_horizontal">
<TextView android:id="#+id/frame_shot1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-" android:textSize="18dip" android:textColor="#000000" />
<TextView android:id="#+id/frame_shot2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="-" android:textSize="18dip" android:textColor="#000000" />
</LinearLayout>
<TextView android:id="#+id/frame_total" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="---" android:textSize="38dip" android:textColor="#000000"/>
</LinearLayout>
buuuuuuuuuuuuuuuuut , i got a problem, there is some blank space at the beginning and end of the gallery with no items. the thing is that my gallery has many items on it that u can actually scroll horizontally, but i wanna get rid of those spaces so the very first thing on the very left of the gallery is the first item, and the very last when u scroll to the very right is the right item.
Edit 08/16 Still with the same problem back in the project, here i leave an image of exactly what is what I'm trying to get rid of that is the black space at the beginning (also is at the end of the gallery at the other side)

The reason you get the blank space on the left is simply because there are no more items to display to the left of the first item (centred in the view). I would assume that the same problem arises to the right of the last item as well.
To properly solve this one will have to decide on what to display when there are no more items, but I will give some ideas:
(1) Increasing the width of the gallery items to the same width as the gallery will only show one item at a time, thus the user will never be able to scroll to the empty space.
(2) To display a solid color or an image in the blank space I would assume setting the android:background attribute of the gallery.
(3) Create a buffer in the beginning and end of your adapter, consisting of the last/first items respectively, and when the user scrolls far enough in the buffer, jump to the matching item at the other end of the gallery for a infinite "carousel" gallery.

Try:
int position=1;
void android.widget.AbsSpinner.setSelection(int position)

One thing you can try is to check if there's more than one item. If there is, set the selection on the gallery to be the second item.

Your probably talking about the fading edge length.
http://developer.android.com/reference/android/view/View.html#setFadingEdgeLength(int)
Try
setFadingEdgeLength(0);
Or
setHorizontalFadingEdgeEnabled(false);
Try changing your layout for the gallery width to fill parent as well instead of wrap content:
<Gallery android:id="#+id/galleryid"
android:layout_width="fill_parent"

set the margin of the gallery to -(metrics.widthPixels)+itemWidth, the blank space is hide.
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
params.setMargins(-(metrics.widthPixels)+itemWidth,0,0,0);
gallery.setLayoutParams(params);

I've just spent with this issue 2 hours and finally found a solution for myself. I have a Gallery, with custom LinearLayout elements. I want to display just 1 element a time without any padding on the start nor on the end.
After many tries I found that, if I set the minWidth parameter of every Item to a big number (android:minWidth="1000dp") my problem is solved. Don't know if it is suitable for your issue. Good Luck
Peter B.

Related

Android ListView cutting off items wider than the first item

I have a Listview inside of a HorizontalScrollView. The listview holds file paths, and the horizontal scroll view is intended to eliminate the need to wrap the longer paths.
Everything is working exactly as desired with the exception that any items longer than the first item in the listview are being cut of at the length of the first item (whatever the width of the first item, none of the other items will scroll past that width).
Here is the section of the layout that is giving me trouble:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/layoutListView"
android:orientation="vertical"
android:layout_below="#+id/spFileTypes">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/lvItems"/>
</HorizontalScrollView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text=""
android:id="#+id/tvStatus"/>
</LinearLayout>
Here is a screenshot of the issue:
The image is scrolled all the way to the right. The third item is cutting off ".php". I have tried this with long and short file names, lists of many (upper double digits) and lists with just a few, in each case, it seems the width limit is dependent of the width of the first item.
Whenever the lists changes, it always limits its width to whatever the first element is.
The desired behavior is to have it match the width of the widest item.
I've googled my heart out, dug through the official documentation, and I'm stumped. Any help is greatly appreciated :)
Instead of wrapping the ListView in HorizontalScrollView, try this:
<ListView
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"/>

Android listview item display text over image using array adapter

I have overloaded the getView method of listview to populate custom style of list item.
This is what currently it looks like:!!
Red color is to just show the background of listview item
Here I have used 3 controls: Imageview for image, 2 text views (one top, one bottom).
Problem here is the height of listview item is getting increased. I want two textviews over the image not above or below. To someextent I know the root cause of this problem but don't know how to fix it.
Here is the layout of listview item:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<ImageView android:id="#+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:scaleType="fitCenter"/>
<TextView android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#FFFFFF"
android:layout_marginLeft="10dp"
android:layout_marginTop="2dp"
android:layout_alignLeft="#+id/imgIcon"
android:layout_alignTop="#+id/imgIcon"
android:layout_alignBottom="#+id/imgIcon"/>
<TextView android:id="#+id/txtTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom"
android:textStyle="bold"
android:textSize="18sp"
android:textColor="#FFFFFF"
android:layout_marginLeft="10dp"
android:layout_marginBottom="5dp"
android:layout_alignLeft="#+id/imgIcon"
android:layout_alignTop="#+id/imgIcon"
android:layout_alignBottom="#+id/imgIcon"/>
The problem is i'm using png image for Imageview and their size is getting increased in some aspect ratio. In case I hard code the height of listview item layout then, specifically on my phone screen size, things start appearing good but on some different screen size things get totally worse (which makes sense too).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:padding="5dp" >
Would be great if someone can explain about how to do it. Main problem is to display text over an image (and image is not same). Thanks.
Update: My major problem is I don't have the bit vector of image instead a PNG and it tries to scale up the image. (setting scale type to center-fit could be an option but would it work on background resourcE?. Here is the output if I set image as a background for listview item and two texts over it.
Ok, when calling getView() in your CustomArrayAdaptor, rather than set the ImageView bitmap to the image you have (what you are currently doing, I believe), instead call View.setBackgroundResource(R.drawable.yourimage.png) on your view after you have infalted it. The equivalent in xml is below:
android:background="#drawable/yourimage".
If you need more information, let me know.
If you're using solid colors as the backgrounds, and you intend to support a variety of screen sizes, I would think it might be easier to use a background color fill on the text views, with the text views stacked and aligned such that there's no borders. Then it would not have any stacking issues (a simple Linear Layout would work) and it would be scalable with no processing of images.

Mimicking the Gmail app label listing

I'm trying to build a layout for my ListView items similar to the Gmail app's listing of labels, where it has the label text on the left and the count to the right. What I have mostly works, except with long text. What I have results in the text overlapping the count.
This is what I'm trying to mimic:
As you can see, the bottom label isn't wrapping where the top label is (read below for more details on this).
When both labels have a count, the count lineup on each row:
With what I have there should be a 3 showing for the last item but it's getting overlapped. Also, I'd like the "count" TextView to lineup on each row the same way the Gmail app is (center, right aligned, I guess?):
Layout code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="1"
>
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:padding="10dp"
android:gravity="left"
android:layout_weight=".75"
/>
<TextView
android:id="#+id/count"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="right|center_vertical"
android:padding="10dp"
android:layout_weight=".25"
/>
</LinearLayout>
I know when you're using layout_weight you're supposed to set the layout_width to 0px, however, this results in every row being cutoff at the same spot. I only want the text wrapping if it goes longer than the count TextView.
I am not good with Android layouts, I think they are extremely frustrating to work with, so this may be something easy. Thanks.
You should be able to prevent the views from overlapping by using a RelativeLayout instead of your LinearLayout, using the layout_toRightOf or layout_toLeftOf XML attributes to position the views relative to one another.
Figured it out. I needed to add android:layout_toLeftOf="#+id/count" to the first TextViewwhich Ernir answered above

Scrolling between views

I'm currently working on a game for android.
I have three ImageView's next to each other, they're positioned next to each other using the "android:layout_toRightOf". The views are located within a RelativeLayout tag. Each of these views are centered into the middle of the screen using "android:scaleType="fitCenter"" and they fill the entire screen.
I'm attempting to implement a horizontal scroll from one view to another so that I basically get one view on my screen at a time.
Here is the code that I'm currently using
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="none">
<RelativeLayout android:id="#+id/GameBg"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="#+id/GameImageContainer3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:layout_toRightOf="#+id/GameImageContainer2"
/>
<ImageView android:id="#+id/GameImageContainer2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:layout_toRightOf="#+id/GameImageContainer1"
/>
<ImageView android:id="#+id/GameImageContainer1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
/>
</RelativeLayout>
</HorizontalScrollView>
What I'm currently getting is three images next to each other -- but sometimes they take up less then an entire screen. I want both the left and right padding to be correct, so that I can only see one image at a time.
Any ideas?
Have you tried the Gallery Widget. It seems to be what you are looking for. Be sure to also check out the Gallery tutorial.
Try using a ViewFlipper
http://www.androidpeople.com/android-viewflipper-example/

How to get UI to look right

I am having a problem getting the ListView to display properly. It currently looks like this with the following xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/favs_main">
<Button
android:text="Return to Home"
android:id="#+id/return_button"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:textSize="15sp"/>
<ListView
android:id="#+id/favsListView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"
android:layout_above="#id/return_button"/>
</RelativeLayout>
If you notice the list is down on the screen. I want it to be just below the favorites text instead of just above the return to home button. The catch however is that I always want the button to show and the list view to just occupy the space between the favorites text and the button. The text is from the background image so I can't just align below that. So even with 100 items I would still like to show the button.
Thanks for the help
If the word "favorites" is part of a background image as suggested in the RelativeLayout's background attribute, then you won't be able to align an element below it without using hacky margins or something to that effect. If you want to align an element below the word, separate that into a different ImageView and set the layout_below of the ListView to the id of that ImageView. To get an element to align properly in between two other elements, use a combination of layout_above and layout_below.
Couldn't you just align the ListView to the Parents' Top and set a margin for the ListView so that it is below the Text of the Background?
Also you could change the background to provide the Text in an ImageView and align the ListView to be below the ImageView.
Instead of trying to make a persistent View always show up under the ListView and align it (which you can do, see other suggestions), you might want to take a look at using a footerView:
http://developer.android.com/intl/de/reference/android/widget/ListView.html#addFooterView
"Add a fixed view to appear at the bottom of the list."
Note that it can be another layout too if you eventually need to do more than just one Button.
this my listview which have multiple entries and textview and button fixed in the botton. i haven't inserted background. try this hope it will help.
http://www.techuv.com/layout-with-butoon-and-textview-fixed-in-bottom/
You could use a simple LinearLayout and use the weight attribute on the ListView :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#drawable/favs_main">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ListView
android:id="#+id/favsListView"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"/>
<Button
android:text="Return to Home"
android:id="#+id/return_button"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"
android:textSize="15sp"/>
</LinearLayout>

Categories

Resources