Reputation: 1355
I need to create new activity in my project, and I want to show pictures. The layout that I want to create is like that.
All heights must have "wrap_content" property.
Which layouts I must use?
Upvotes: 2
Views: 258
Reputation: 2507
Try this:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >
<GridView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="66" >
</GridView>
<GridView
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="33" >
</GridView>
</LinearLayout>
<GridView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</GridView>
</LinearLayout>
Note: you can use any other View instead of GridView just make sure the attributes are the same.
Upvotes: 3
Reputation: 710
Consider using a TableLayout or a GridView and use the attribute layout_weight on the children.
Your first child (66%) can have a layout weight of 2, the second (33%) a layout of 1.
Then the first child will occupy 2/3 of the width (66%) and the second child 1/3, that is 33%.
And use the layout_span attribute to expand the last view on the two columns.
For example :
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="*" >
<TableRow>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="2" />
</TableRow>
</TableLayout>
Also see that question for an explanation on layout_weight.
Upvotes: 0
Reputation: 3704
Why do you insist on using wrap_content? You have "fixed" width of boxes (66% and 33%). You can use sp/dp units to achieve this, I am sure. With some tweaking, of course.
For more info regarding this topic go to http://developer.android.com/guide/practices/screens_support.html and What is the difference between "px", "dp", "dip" and "sp" on Android?
Upvotes: 0
Reputation: 4636
I think you want to create an StaggeredGridView.
StaggeredGridView is a modified version of Android’s experimental StaggeredGridView. The StaggeredGridView allows the user to create a GridView with uneven rows similar to how Pinterest looks. Includes own OnItemClickListener and OnItemLongClickListener, selector, and fixed position restore.
Use this library.
Hope this helps :)
Upvotes: 0