1

I'm pretty new to android development, and I've been having some problems getting my layout to show the way I want it to. Basically what I want is four side-scrolling views containing an images with labels. The number of images isn't known until run-time. I want the side-scrolling views to be scalable to different sizes.

Right now, the setup I have looks something like this: Main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff" android:id="@+id/build">
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_weight="1"
    android:layout_height="0dp" android:background="#ddd" android:id="@+id/ahsv" />
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_weight="1"
    android:layout_height="0dp" android:background="#ddd" android:id="@+id/ihsv" />
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_weight="2"
    android:layout_height="0dp" android:background="#ddd" android:id="@+id/mhsv" />
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_weight="3"
    android:layout_height="0dp" android:background="#ddd" android:id="@+id/rhsv" />

viewitem.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:background="#fff">

<ImageView android:id="@+id/image" android:layout_height="fill_parent"
    android:layout_width="fill_parent" android:scaleType="center" />

<TextView android:id="@+id/title" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:textColor="#000"
    android:layout_gravity="center_horizontal|bottom" />

There's also a LinearLayout that goes inside of the HorizontalScrollViews

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#fff"
android:id="@+id/horizll"/>

At this point my code just instantiates a bunch of these viewitems using LayoutInflator, adds them to the LinearLayout (horizll), that was inflated and added to the HorizontalScrollView. (all of this is done in onCreate())

The code works almost as intended. I have four side-scrolling lists that have heights corresponding to their weights. However, the images inside of these are stuck at their default size, in other words, they are not scaling with the height of the HorizontalScrollView.

What am I doing wrong?

Thanks in advance for the help

Ross Aiken
  • 912
  • 1
  • 6
  • 16

2 Answers2

1

Well I eventually figured it out. I ended up looking around a lot more on SO, and found a question on using ViewTreeObserver. After setting up an appropriate VTO, I was able to specify the minimum width and height of the FrameLayout. A bit hackish, but it gets the job done.

Community
  • 1
  • 1
Ross Aiken
  • 912
  • 1
  • 6
  • 16
  • I couldn't get it to work with minimum width and height but I used setLayoutParams() on the ImageView and that worked for me. – richy Nov 14 '12 at 06:00
0

try specifying scaleType in ImageView. For instance,

android:scaleType="fitXY" 

will stretch small image up to ImageView's boundaries. You might also need to specify

android:adjustViewBounds="true"

to keep aspect ratio.

Mcingwe
  • 2,070
  • 2
  • 18
  • 17
  • Well after doing what you suggested, it now stretches the images to the width of the text. Thanks for the quick reply – Ross Aiken Oct 27 '11 at 15:47