Above all answers are right but In a case you need visible and gone features then this pragmatically method will work well
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal">
<Button
android:id="@+id/btnOne"
android:layout_width="120dp"
android:layout_height="match_parent"></Button>
<Button
android:id="@+id/btnTwo"
android:layout_width="120dp"
android:layout_height="match_parent"></Button>
<Button
android:id="@+id/btnThree"
android:layout_width="120dp"
android:layout_height="match_parent"></Button>
</LinearLayout>
float width=CommonUtills.getScreenWidth(activity);
int cardWidth=(int)CommonUtills.convertDpToPixel (((width)/3),activity);
LinearLayout.LayoutParams params =
new LinearLayout.LayoutParams(width,
LinearLayout.LayoutParams.MATCH_PARENT);
btnOne.setLayoutParams(params);
btnTwo.setLayoutParams(params);
btnThree.setLayoutParams(params);
public class CommonUtills {
public static float getScreenWidth(Context context) {
float width = (float) 360.0;
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
width = displayMetrics.widthPixels / displayMetrics.density;
return width;
}
}