Circular Buttons In Linearlayout:vertical
Solution 1:
Well. For one, all your layout_widths in the LinearLayouts children are set to match_parent. After the first child renders, then there won't be room for anything else because it will take up all the space.
Secondly, I would highly suggest against using all the tags. Instead I would just set padding (or margins) for your buttons.
Solution 2:
If I understand correctly, you want the View
s inside the LinearLayout
to be spaced with weight
. If so, then android:layout_weight
should be on each View
and not the LinearLayout
. The LinearLayout
would have the android:weightSum
and each View
would have the weight
of say 1. But you don't even need weightSum
if you want them all spaced evenly.
<LinearLayout
android:id="@+id/left_bar"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="8"> // Try removing this and add weights to your views
I don't know if this will fix your problem but I would start with that
Solution 3:
I had the same problem. I had to have 4 circular buttons in a horizontal LinearLayout equally spaced.
<LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"android:layout_marginBottom="10dp" ><Buttonandroid:id="@+id/btn1"style="@style/BotonCircular"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="0.2"android:background="@drawable/boton_circulo_negro" /><Viewandroid:layout_weight="0.033"android:layout_width="0dp"android:layout_height="match_parent"
/><Buttonandroid:id="@+id/btn2"style="@style/BotonCircular"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="0.2"android:background="@drawable/boton_circulo_negro" /><Viewandroid:layout_weight="0.033"android:layout_width="0dp"android:layout_height="match_parent"
/><Buttonandroid:id="@+id/btn3"style="@style/BotonCircular"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="0.2"android:background="@drawable/boton_circulo_negro" /><Viewandroid:layout_weight="0.033"android:layout_width="0dp"android:layout_height="match_parent"
/><Buttonandroid:id="@+id/btn4"style="@style/BotonCircular"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="0.2"android:background="@drawable/boton_circulo_negro" /></LinearLayout>
And to make them all of the same height I placed this code inside onCreate on my Activity
finalButtonbtn1= (Button) findViewById(R.id.btn1);
finalButtonbtn2= (Button) findViewById(R.id.btn2);
finalButtonbtn3= (Button) findViewById(R.id.btn3);
finalButtonbtn4= (Button) findViewById(R.id.btn4);
ViewTreeObservervto= btn1.getViewTreeObserver();
vto.addOnGlobalLayoutListener(newViewTreeObserver.OnGlobalLayoutListener() {
@OverridepublicvoidonGlobalLayout() {
btn1.setHeight(btn1.getWidth());
btn2.setHeight(btn1.getWidth());
btn3.setHeight(btn1.getWidth());
btn4.setHeight(btn1.getWidth());
}
});
Hope this helps someone with the same problem.
Post a Comment for "Circular Buttons In Linearlayout:vertical"