Eclipse-安卓应用程序-方块菜单



Eclipse-Android应用程序我正在尝试制作一个由"方形"按钮组成的菜单——一排3个按钮-每个按钮都有一个背景图像。。。

我能够制作同等重量的柱子,但我不知道如何使按钮的高度始终等于它们的宽度,因为:-我将来会在应用程序中添加更多的行,所以我不希望布局特定于特定数量的行;即:无论行数是多少,按钮都应该是方形的(当然,在任何设备屏幕大小上)-我希望背景图像能够根据按钮进行调整;即:按钮保持正方形,背景图像符合

到目前为止,这是我的代码:(只有三行具有相同的bg图像

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never" >
<LinearLayout 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="@drawable/velocity_icon"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="@drawable/velocity_icon"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="@drawable/velocity_icon"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="@drawable/velocity_icon"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="@drawable/velocity_icon"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="@drawable/velocity_icon"
/>
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="@drawable/velocity_icon"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="@drawable/velocity_icon"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:background="@drawable/velocity_icon"
/>
</LinearLayout>
</LinearLayout>
</ScrollView>

我认为您必须自定义一个列表视图,才能将菜单添加到中

要使形状始终为正方形,必须使用九个面片参见此处

最新更新