Thursday, March 29, 2012

Re: [android-developers] Re: Different sized images, arrangement and layout problem

Hi, I have attached the view that I have made for an application. I am struggling to remove the grey background and arranging the images properly. Cant figure out why the grey background is showing.

The layout xml is as shown below. I add imageViews with images to the linear layout. imageView has width and height set to wrap_content, and its background is grey:

<ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/spinner" >

        <LinearLayout 
            android:id="@+id/imagesHolder"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:baselineAligned="false"
            >
         <LinearLayout 
             android:id="@+id/imagesHolder1"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:layout_weight="10"
             android:orientation="vertical">
         </LinearLayout>    
         <LinearLayout 
             android:id="@+id/imagesHolder2"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:layout_weight="10"
             android:orientation="vertical">
         </LinearLayout>    
         <LinearLayout 
             android:id="@+id/imagesHolder3"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:layout_weight="10"
             android:orientation="vertical">
         </LinearLayout>    
            
        </LinearLayout>
    </ScrollView>

On Thu, Mar 29, 2012 at 3:55 PM, EhyehAsherEhyeh <jacobsen.arild@gmail.com> wrote:
I don't believe so, but I am not absolutely certain it's impossible.
As for keeping track of which layout to add to in my example, I'd just
use an array of LinearLayouts, which you find on Activity creation,
then keep an int to increment each time you add an image and use that
modulus 3 (or however many columns you want) to index the array:

linearLayoutArray[index%3].addView(...);
index++;

On Mar 29, 11:30 am, Farhan Tariq <farhan....@gmail.com> wrote:
> In that case, I would have to add to one of the 3 linear layouts usings
> their id, no? I would also need to keep track of which linear layout I
> added to first, so that I add the next image to the next one. There would
> be a lot of 'if's executing at run time.
>
> Can I have a gridView with different heights of images, fitting together
> perfectly?
>
> On Thu, Mar 29, 2012 at 12:28 PM, EhyehAsherEhyeh
> <jacobsen.ar...@gmail.com>wrote:
>
>
>
>
>
>
>
> > ScrollView can only hold one view, so put a LinearLayout in there
> > (orientation horizontal). Put three LinearLayouts in that
> > LinearLayout, use layout_weight to give them equal spacing (doesn't
> > matter what you set each weight to as long as they each get equal
> > weight and as long as those three are the only immediate children of
> > the wrapping LinearLayout.) The weights indicate how large a portion
> > of the free space each layout should get, after they've each been
> > allotted the width they request in layout_width, so set each of them
> > to width="0dp", which means all the space is "free space" and the
> > weights should distribute all available width. Once that's done you
> > have your three columns, so just set each imageview you add to them to
> > have width="fill_parent" and an appropriate scaling type and you're
> > done.
>
> > On Mar 29, 1:12 am, Farhan Tariq <farhan....@gmail.com> wrote:
> > > Hi everyone,
>
> > > I need to make an application that would show a number of images on the
> > > screen. The images can vary in height and width. I want to be able to
> > show
> > > the images in a scrollView, such that there are no empty spaces between
> > > images. So...
>
> > > 1 -  its a scrollable view,
> > > 2 - with 3 columns. Each column has a fixed width,
> > > 3 - and each image of different heights and widths adjusts its width
> > > according to the width of the column.
>
> > > The number of images is not known, and they would be added to the
> > > scrollView at runtime. How do I construct this view? Would scrollview be
> > a
> > > good choice? Can I have a gridView for the purpose?
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscribe@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment