我对布局有困难。布局:拉伸的背景图片
作为我的第一个开发项目,我试图制作一个简单的天文台。 我想要在背景中显示一个天文台的图片,并且在应用程序的底部有开始和停止按钮 ,并排并填充屏幕宽度。
这是我的最佳拍摄,但我不满意。
所有小部件都放置正确,但... 我的背景被拉伸,我的按钮似乎垂直压缩,甚至底部的文本有点裁剪。
我发现,如果我改变这些线
android:layout_width="fill_parent"
android:layout_height="fill_parent"
通过
android:layout_width="wrap_content"
android:layout_height="wrap_content"
背景是OK,则按钮太..但所有部件被放置在活动的中心。
我该如何解决这个问题?
顺便说一句,如果我想让我的按钮并排,我选择了更好的解决方案吗?
感谢您的帮助!查尔斯。
...现在我的XML ....
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/background"
tools:context=".Chronosv1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="2" >
<Chronometer
android:id="@+id/chronometer1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="50"
android:text="START" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="50"
android:text="STOP" />
</LinearLayout>
我试过RelativeLayout的。 我不知道如何在不使用填充的情况下使用两个相同大小的按钮,如果您希望您的应用在不同的屏幕上运行,我不认为这是个好主意。
无论如何,我想出了这个,但我仍然有我的拉伸图像和我的按钮不具有相同的大小。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
tools:context=".Chronosv1" >
<Chronometer
android:id="@+id/chronometer1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Start" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/button1"
android:text="Stop" />
1)最有可能的是,你需要比'LinearLayout'更先进的东西; (2)你的“Chronometer”组件是什么? –
Chronmeter是一个Android小部件 android.widget.Chronometer –