0

I have a little problem when it comes to programming my Android app. I want to have 2 Images beside each other that could be different sizes, they could also be the same size but that's not the problem for me. One of them can be REALLY large while the other one can be really small that's the scenario when it gets messy. I want an image to only be allowed to use 50% of the screen. How do I do this preferred in the layout file?

EDIT: Adding this text here because I think it helps describing the problem. ImageA is 200 px wide and ImageB is is only 20px. The screen is 100 px wide. So when I add ImageA to the screen it's going to scale it so it's only 50px, and if I add ImageB to the screen it's going to keep the 20 px size and not be resized at all.

I did a very beautiful image that shows what I want to do :)

enter image description here

Thanks in advance

Ravi
  • 34,851
  • 21
  • 122
  • 183
eXpliCo
  • 33
  • 4

2 Answers2

0

You can put them into a linear Layout with horizontal orientation and assign the same weight to both of them.

fedorSmirnov
  • 701
  • 3
  • 9
  • 19
  • Well if I assign the same weight to them the larger is going to push the smaller image aside if the smaller image doesn't fill up the 50% space. – eXpliCo Jan 21 '14 at 19:31
  • Then put each of the images into a linear layout of themselves and let the linear layouts weights be equal. – fedorSmirnov Jan 21 '14 at 19:35
0

Since you didn't showed us your own layout I am showing an example using buttons

 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="5">

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="1" />

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:text="2" />

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="3" />

    </LinearLayout>

See the result.

Modify it according to your own needs.

Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
  • I get the same problem with this. If I would add a very wide image in the first (1) view then it will push 3 and 2 to the right side. And I don't want that to happen. – eXpliCo Jan 21 '14 at 19:34
  • So what do you want when big image comes? Automatic resizing? – Rohan Kandwal Jan 21 '14 at 19:36
  • Ok here it is lets say I have 2 images. ImageA is 200 px wide and ImageB is is only 20px. The screen is 100 px wide. So when I add ImageA to the screen it's going to scale it so it's only 50px, and if I add ImageB to the screen it's going to keep the 20 px size and not be resized at all. Hope that clears it up. – eXpliCo Jan 21 '14 at 19:47