レイアウトに問題があります。
私の最初の開発プロジェクトとして、単純なクロノメーターを作ろうとしています。背景にクロノメーターの写真と、アプリケーションの下部にある開始ボタンと停止ボタンを並べて画面の幅いっぱいに表示したいと考えています。
これが私のベスト ショットですが、満足していません。
すべてのウィジェットは適切に配置されていますが... 背景が引き伸ばされ、ボタンが垂直方向に圧縮されているように見えます。下部のテキストも少しトリミングされています。
これらの行を変更すると、
android:layout_width="fill_parent"
android:layout_height="fill_parent"
に
android:layout_width="wrap_content"
android:layout_height="wrap_content"
背景は問題ありません。ボタンも..しかし、すべてのウィジェットはアクティビティの中央に配置されています。
どうすればこれを修正できますか?
ところで、ボタンを並べて配置したい場合、より良い解決策を選択しましたか?
ご協力いただきありがとうございます !チャールズ。
...そして今私の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を試しました。パディングを使用せずに同じサイズの 2 つのボタンを使用する方法がわかりません。アプリを異なる画面で実行したい場合は、良い考えではないと思います。
とにかく私はこれを思いつきましたが、まだストレッチされたイメージがあり、ボタンのサイズが同じではありません。
<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" />