ANDROID: Weighted Linear List Buttons disappear

438 views Asked by At

I have seen many posts about this and have tried many of the solutions but for some reason nothing is working. I just want the buttons to share equal space... Can you please look at my xml code and see if something is wrong? Thanks!


    
        
        
        
        

<ScrollView android:id="@+id/scrollview1" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:weightSum="120"> <Button android:id="@+id/btn_mission" android:layout_width="0dp" android:layout_height="wrap_content" android:background="#8D8BB7" android:layout_weight="20" android:text="Mission"> </Button> <Button android:id="@+id/btn_news" android:layout_width="0dp" android:layout_height="wrap_content" android:background="#8D8BB7" android:layout_weight="20" android:text="News/Events"> </Button> <Button android:id="@+id/btn_studentservices" android:layout_width="0dp" android:layout_height="wrap_content" android:background="#8D8BB7" android:layout_weight="20" android:text="Student Services"> </Button> <Button android:id="@+id/btn_facultyservices" android:layout_width="0dp" android:layout_height="wrap_content" android:background="#8D8BB7" android:layout_weight="20" android:text="Faculty Services"> </Button> <Button android:id="@+id/btn_staff" android:layout_width="0dp" android:layout_height="wrap_content" android:background="#8D8BB7" android:layout_weight="20" android:text="Staff"> </Button> <Button android:id="@+id/btn_library" android:layout_width="0dp" android:layout_height="wrap_content" android:background="#8D8BB7" android:layout_weight="20" android:text="Library"> </Button> </LinearLayout> </ScrollView> </LinearLayout>

EDIT: It seems to be something to do with setting the background I removed the background and everything shared equal space except you still must scroll.

2

There are 2 answers

2
Dalmas On BEST ANSWER

Your LinearLayout has a vertical orientation, so instead of android:layout_width="0dp" you should use android:layout_height="0dp".

0
Nick Campion On

Try removing android:weightSum="120" and setting the android:layout_weight="20" to android:layout_weight="1" on all of the buttons.