Reputation: 4743
I have a GridView
and com.daimajia.slider.library.SliderLayout
inside a LinearLayout
. And this LinearLayout
is a child of a ScrollView
. I have given weight for GridView
and SliderLayout
. The problem is that SliderLayout
is not expanding
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:focusableInTouchMode="true"
android:scrollbars="none" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_main_black"
android:orientation="vertical" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9.5"
android:minHeight="335dp" >
<com.daimajia.slider.library.SliderLayout
android:id="@+id/advertiseSlider"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.daimajia.slider.library.Indicators.PagerIndicator
android:id="@+id/custom_indicator"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_gravity="bottom"
android:gravity="center"
custom:selected_color="#FFFFFF"
custom:selected_height="8dp"
custom:selected_padding_left="3dp"
custom:selected_padding_right="3dp"
custom:selected_width="8dp"
custom:shape="oval"
custom:unselected_color="#555555"
custom:unselected_height="4dp"
custom:unselected_padding_left="3dp"
custom:unselected_padding_right="3dp"
custom:unselected_width="4dp" />
</FrameLayout>
<ScrollableGridView
android:id="@+id/categorylist"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="2dp"
android:layout_weight="5"
android:background="@color/app_main_black"
android:drawSelectorOnTop="true"
android:horizontalSpacing="2dp"
android:numColumns="2"
android:stretchMode="columnWidth" />
</LinearLayout>
</ScrollView>
Upvotes: 0
Views: 988
Reputation: 7974
try this.It calculates grid view height based on children
public void setGridViewHeightBasedOnChildren(GridView gridView, int columns) {
ListAdapter listAdapter = gridView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = 0;
int items = listAdapter.getCount();
int rows = 0;
View listItem = listAdapter.getView(0, null, gridView);
listItem.measure(0, 0);
totalHeight = listItem.getMeasuredHeight();
float x = 1;
if( items > columns ){
x = items/columns;
rows = (int) (x + 1);
totalHeight *= rows;
}
ViewGroup.LayoutParams params = gridView.getLayoutParams();
params.height = totalHeight;
gridView.setLayoutParams(params);
}
After you have called setAdapter on your gridview, just call
setGridViewHeightBasedOnChildren( <yourGridView> , <no of grid view columns> )
Upvotes: 1
Reputation: 2436
android:layout_weight is used when you have declared a android:weightSum on your LinearLayout
android:weightSum = "14.5"
Upvotes: 0