我正在研究Android应用程序的布局,但我发现所有按钮都在Eclipse中以自动方式固定在列中。我应该怎么做才能使它像链接中显示的应用程序一样的位置?感谢在Eclipse中制作所需的布局
http://www.dcemu.co.uk/vbulletin/threads/335622-Android-oscilloscope
我正在研究Android应用程序的布局,但我发现所有按钮都在Eclipse中以自动方式固定在列中。我应该怎么做才能使它像链接中显示的应用程序一样的位置?感谢在Eclipse中制作所需的布局
http://www.dcemu.co.uk/vbulletin/threads/335622-Android-oscilloscope
您可以通过具有垂直LinearLayout
含,每个包含2个按钮几个水平LinearLayout
小号拿到按钮2列。给这些按钮设置相同的权重以均匀分布它们,并留出一些余量以使它们看起来不那么混乱。
E.g.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button 1" />
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button 2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button 3" />
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Button 4" />
</LinearLayout>
</LinearLayout>
或者如果柱子将是很长的,你可以使用含2点垂直线性布局,水平线性布局,按钮添加到这些。
或者您可以使用2列的TableLayout
并且包含按钮的TableRows
(我通常发现表格布局更难以使用,也许这只是我)。
我发现在Eclipse中编写xml更容易,而不是用图形编辑器摆弄,然后切换到图形编辑器,每隔一段时间检查一下显示的方式。在线查看几个示例布局,您很快就会明白。
要正确模拟该布局,请按照mihail的建议从RelativeLayout
开始,然后使用它来定位其他布局(例如按钮的线性布局)和视图。
您可以在main.xml
文件中使用RelativeLayout
而不是LinearLayout
。 在此布局中,您可以将组件放置在布局中的任何位置,但组件会彼此放置在relatively
之间。 您可以使用混合布局来使您的视图看起来健全。也可以尝试使用布局方向,即垂直或水平,
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
阅读关于相对布局:http://developer.android.com/reference/android/widget/RelativeLayout.html,你也可以谷歌的例子 - 有很好的解决方案:)祝你好运 – mihail 2012-03-08 08:57:26