layout_weight = "1"とlayout_width = "0dp"を使用して均等にスペースを取る4つのボタンがあります。しかし、大きなタブレットレイアウトではボタンが広がりすぎて醜いので、すべてのボタンのmaxWidthを設定し、代わりにLinearLayoutの両側に空白を入れたい(4つのボタンが中央に集中している)。しかし、StackOverflowを介してクロールすると、多くの人が一緒に動作しないと言います。私が上でやりたいことを達成する方法はありますか?layout_weightが均等に配置されていてもmaxWidthを持つスペーシングボタン
TL; DR:一定幅以下
- (例えば、100dp)は、すべての4つのボタンが等間隔に配置されています。
レイアウトにボタンが100dpより大きい必要がある場合、4つのボタンはすべて100dpの幅に設定され、一緒に貼り付けられ、レイアウトの両側にスペースが残されます。
<LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/layout_height" android:background="@drawable/layout_background" android:orientation="horizontal"> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/button_background"/> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/button_background"/> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/button_background"/> <Button android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@color/button_background"/> </LinearLayout>
あなたは答えを得ましたか? – DKV