我對佈局有困難。佈局:拉伸的背景圖片
作爲我的第一個開發項目,我試圖製作一個簡單的天文臺。 我想要在背景中顯示一個天文臺的圖片,並且在應用程序的底部有開始和停止按鈕 ,並排並填充屏幕寬度。
這是我的最佳拍攝,但我不滿意。
所有小部件都放置正確,但... 我的背景被拉伸,我的按鈕似乎垂直壓縮,甚至底部的文本有點裁剪。
我發現,如果我改變這些線
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 –