I created a component that would be a button bar at the bottom of the screen. She should respect both the portrait and landscape the width of the screen at least. If the width of the component passes the screen I am using a HorizontalScrollView. The component is not getting the minimum width of the screen:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:orientation="horizontal" >
<Button
android:id="@+id/btn1"
style="@style/ButtonApp_Theme"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="25"
android:background="@color/Transparente"
android:drawableTop="@drawable/1"
android:padding="10dp"
android:text="@string/1"
android:textColor="@color/White"
android:textSize="16sp" />
<Button
android:id="@+id/btn2"
style="@style/ButtonApp_Theme"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="25"
android:background="@color/Transparente"
android:drawableTop="@drawable/2"
android:padding="2dp"
android:text="@string/2"
android:textColor="@color/White"
android:textSize="16sp" />
<Button
android:id="@+id/btn3"
style="@style/ButtonApp_Theme"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="25"
android:background="@color/Transparente"
android:drawableTop="@drawable/3"
android:padding="2dp"
android:text="@string/3"
android:textColor="@color/White"
android:textSize="16sp" />
<Button
android:id="@+id/btn4"
style="@style/ButtonApp_Theme"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_weight="25"
android:background="@color/Transparente"
android:drawableTop="@drawable/4"
android:padding="2dp"
android:text="@string/4"
android:textColor="@color/White"
android:textSize="16sp" />
</LinearLayout>
In the layout where I insert the created component I'm using android: layout_width="fill_parent" and even though the width width is not being respected (the width of the screen being greater than that of the component).
public class BottomBarButton extends HorizontalScrollView implements
OnClickListener {
private Button btn1;
private Button btn2;
private Button btn3;
private Button btn4;
private LayoutInflater inflater;
private Context context;
public BottomBarButton(Context context) {
super(context);
intitializer(context);
}
public BottomBarButton(Context context, AttributeSet attrs) {
super(context, attrs);
intitializer(context);
}
private void intitializer(Context context) {
this.context = context;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.layout_bottom_bar_button, this);
btn1 = (Button) findViewById(R.id.btnV1);
btn1.setOnClickListener(this);
btn2 = (Button) findViewById(R.id.btn2);
btn2.setOnClickListener(this);
btn3 = (Button) findViewById(R.id.btn3);
btn3.setOnClickListener(this);
btn4 = (Button) findViewById(R.id.btn4);
btn4.setOnClickListener(this);
}
@Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.btn1:
Toast.makeText(context, "btn1", Toast.LENGTH_SHORT)
.show();
break;
case R.id.btn2:
Toast.makeText(context, "btn2", Toast.LENGTH_SHORT)
.show();
break;
case R.id.btn3:
Toast.makeText(context, "btn3", Toast.LENGTH_SHORT)
.show();
break;
case R.id.btn4:
Toast.makeText(context, "btn4", Toast.LENGTH_SHORT)
.show();
break;
default:
break;
}
}
}