0

レイアウトに問題があります。

私の最初の開発プロジェクトとして、単純なクロノメーターを作ろうとしています。背景にクロノメーターの写真と、アプリケーションの下部にある開始ボタンと停止ボタンを並べて画面の幅いっぱいに表示したいと考えています。

これが私のベスト ショットですが、満足していません。

すべてのウィジェットは適切に配置されていますが... 背景が引き伸ばされ、ボタンが垂直方向に圧縮されているように見えます。下部のテキストも少しトリミングされています。

これらの行を変更すると、

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" />

4

3 に答える 3

0

私は最終的に解決策を見つけました。

最初の問題: 9 パッチ イメージが他のコンポーネントを隠してしまいました。

解決策:あなたのlinearlayoutにandroid:padding="0dip"を追加してください...ここで私の答えを与えてくれた件名(9パッチの背景で壊れたAndroidレイアウト

2 番目の問題: 画面の正確なサイズで設計したのに、なぜ私の写真が引き伸ばされたのか。これはばかげた質問でした...アクションバーと上の他のバー(バッテリーレベルなど)が原因でした。

これらのバー (テーマに含まれる) を取り除くには、マニフェストで別のバージョンのテーマを使用します。

私は選択します:Theme.Light.NoTitleBar.Fullscreen。

問題は解決しました。

于 2013-05-08T08:49:47.743 に答える
0

これを試すことができますか?IMOで動作するはずです。これは、レイアウトを取得するためのより優れた/確実な方法です。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".Chronosv1" >


<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="5dp"
android:text="Start" />

<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="5dp"
android:text="Stop" />
</LinearLayout>
<Chronometer
android:id="@+id/chronometer1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/layout1" />
</RelativeLayout> 
于 2013-04-19T04:25:17.090 に答える
0

RelativeLayout を試してください ;) これは LinearLayout よりもはるかに扱いやすいと思います。多分あなたはそれがどのように見えるか写真をアップロードすることができます.

于 2013-04-18T09:43:24.507 に答える