0

I am trying to make images in this layout (with id itemslayout) wrap the image rather than match the parent height. The imageviews dont seem to listen to my XML code! What is the solution. Here is the XML:

<LinearLayout android:layout_width="match_parent" android:layout_height="200dp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:orientation="vertical" > <FrameLayout android:id="@+id/pullupTitleBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/orange" android:orientation="vertical" > <xx.xxxxxx.xxxxx.android.ui.views.CustomTextView android:id="@+id/someTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_margin="10dp" android:text="@string/lolperks" android:textColor="@color/white" android:textSize="22sp" /> <Button android:id="@+id/upanddownButton" style="@style/OrangeSmallButton" android:layout_width="37dp" android:layout_height="34dp" android:layout_gravity="right" android:layout_marginRight="6dp" android:layout_marginTop="6dp" android:background="@drawable/double_arrows" android:contentDescription="UpButton" android:onClick="downButtonClicked" android:scaleY="-1" android:text=" " /> </FrameLayout> <ScrollView android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="pick a card any card " android:textAppearance="?android:attr/textAppearanceSmall" /> <LinearLayout android:id="@+id/itemslayout" android:layout_width="match_parent" android:layout_height="wrap_content" > <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:layout_weight="0.333" > <ImageView android:id="@+id/ImageView02" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/card" /> </FrameLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:layout_weight="0.333" > <ImageView android:id="@+id/ImageView01" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/card" /> </FrameLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.333" android:layout_margin="10dp" > <ImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/card" /> </FrameLayout> </LinearLayout> </LinearLayout> </ScrollView> </LinearLayout> 

here is a screenshot of what is happening. I need it to be wrapping the image not matching the parent. wrap_content

What i want:

enter image description here

10
  • 1
    Why do you have a frame layout for each ImageView? Commented Jan 8, 2014 at 16:53
  • Because I will add other content in here like buttons etc later on :). Commented Jan 8, 2014 at 16:58
  • 2
    I'm almost 100% sure you can't use wrap_content or match_parent if your using layout weight for childs. You are basically saying that it should fit content size(childs size), but your childs refers to the size of the parent(weight). That's strange. Commented Jan 8, 2014 at 17:02
  • so... what is the solution? I still need to have 3 per row that scales to 100% of the screen width. Commented Jan 8, 2014 at 17:04
  • 1
    I'm sorry, I'm not understanding your question. In your title, you are saying that you want linearlayout height match_parent instead of wrap_content but before the screenshot you say you want I need it to be wrapping the image not matching the parent. Commented Jan 8, 2014 at 17:13

1 Answer 1

1

I know it might sound confusing, but try putting one more layout inside of the outermost layout and set the height to wrap_content. With layouts, it causes everything inside of it to wrap content rather than causing the actual layout to do it. You need this buffer layout though so that the outermost layout will still fill the whole screen.

<LinearLayout android:layout_width="match_parent" android:layout_height="200dp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:orientation="vertical" > <FrameLayout android:id="@+id/pullupTitleBar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/orange" android:orientation="vertical" > <xx.xxxxxx.xxxxx.android.ui.views.CustomTextView android:id="@+id/someTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_margin="10dp" android:text="@string/lolperks" android:textColor="@color/white" android:textSize="22sp" /> <Button android:id="@+id/upanddownButton" style="@style/OrangeSmallButton" android:layout_width="37dp" android:layout_height="34dp" android:layout_gravity="right" android:layout_marginRight="6dp" android:layout_marginTop="6dp" android:background="@drawable/double_arrows" android:contentDescription="UpButton" android:onClick="downButtonClicked" android:scaleY="-1" android:text=" " /> </FrameLayout> <ScrollView android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:text="pick a card any card " android:textAppearance="?android:attr/textAppearanceSmall" /> <LinearLayout android:id="@+id/itemslayout" android:layout_width="match_parent" android:layout_height="wrap_content" > <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:layout_weight="0.333" > <ImageView android:id="@+id/ImageView02" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/card" /> </FrameLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:layout_weight="0.333" > <ImageView android:id="@+id/ImageView01" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/card" /> </FrameLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.333" android:layout_margin="10dp" > <ImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/card" /> </FrameLayout> </LinearLayout> </LinearLayout> </ScrollView> 

Sign up to request clarification or add additional context in comments.

7 Comments

I am not sure I understand. My outer layout is already wrapping content?
Your outermost layout is your linear layout. it is matching parent. It may be causing your frame layout to match it. I had trouble with this in a previous project. Try it out and see if it works. I added the linear layout to my original answer look at it to see what I mean.
My outermost layout is actually a relative layout. It has to be because of the Custom classes I include in the real project.
Try adding the linear layout just inside of the other one where I added it. If that doesn't work, I would try using a linear layout instead of relative and nesting the relative somewhere inside for your custom classes. Relative layouts break everything.
Sorry I couldn't help. Its always worth a try because it only takes a minute or so to throw in an extra layout or two.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.