1

小さな画面に7つのボタンをレイアウトしてテストしようとしています(Galaxy young)。スクロールビューを使用しましたが、まだ問題があります(LandScapeモードでは画面がスクロールしません)。

これは私のxmlコードです:

 <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:fillViewport="true">

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="horizontal" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
         android:layout_height="?android:attr/listPreferredItemHeight"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/lieu_depart"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Lieu de prise en charge"
            style="" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentLeft="false"
        android:layout_alignParentRight="false"
        android:layout_below="@+id/linearLayout1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="@dimen/activity_vertical_margin" >

        <Button
            android:id="@+id/button2_date_depart"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:text="Date1" />

        <Button
            android:id="@+id/time_depart5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="70dp"
            android:text="Time1" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout3"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_below="@+id/linearLayout2"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minWidth="@dimen/activity_vertical_margin"
            android:text="Lieu de restitution" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/linearLayout3"
        android:layout_marginTop="@dimen/activity_vertical_margin"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button5_date_arrive"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:text="Date2" />

        <Button
            android:id="@+id/button6_time_arrive"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="70dp"
            android:text="Time2" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/linearLayout4"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/Button03"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Button" />

    </LinearLayout>

</RelativeLayout>
</ScrollView>

編集ポートレートモード:

ここに画像の説明を入力

横長モード:

ここに画像の説明を入力

この問題を制限するには何を使用すればよいですか?

ありがとうございました

4

3 に答える 3

0

ScrollView 内で LienarLayout を使用する必要があります。RelativeLayout は方向を無視し、アイテムを絶対位置に配置する場合に使用します。あなたの xml レイアウトには、変更すべきことがたくさんあります。正確に何が欲しいかを理解するために、レイアウトの画像を送ってもらえますか。

ここにあります:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Starting place" />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Date 1" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Time 1" />
    </LinearLayout>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Arrival place" />
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Date2" />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="50dp"
            android:text="Time2" />
    </LinearLayout>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Submit" />
</LinearLayout>
</ScrollView>

最後のlinearlayout 2番目のボタンにはlayout_marginLeftが含まれていますが、linearlayout重心ではボタンが中央に配置され、このスペースが2つのボタン間で分割されるため、それらの間のスペースを操作できます。

デフォルトではレイアウトは親を埋めますが、2番目の画像には必要に応じて右マージンのようなものがあります.Android構成修飾子を使用できますが、レイアウトxmlを複製しないより良い方法は、values-land修飾子を使用し、パディングを追加できるdimensフォルダーを追加することです値をスクロールビューandroid:paddingRight="@dimen/your_property_name"の最初のレイアウトの子にレイアウトに追加します。dimen リソースの詳細。

于 2013-08-12T16:33:44.090 に答える
0

編集..

これを修正するには、ボタンに「android:layout_below="@id/id of your button」を追加する必要があります。以下を参照してください。

<Button
    android:id="@+id/lieu_depart"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Lieu de prise en charge"
    style="" />

<Button
    android:id="@+id/button2_date_depart"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="50dp"
    android:layout_below="@id/lieu_depart"
    android:text="Date1" />

<Button
    android:id="@+id/time_depart5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="70dp"
    android:layout_below="@id/button2_date_depart"
    android:text="Time1" />

<Button
    android:id="@+id/button4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minWidth="@dimen/activity_vertical_margin"
    android:layout_below="@id/time_depart5"
    android:text="Lieu de restitution" />

<Button
    android:id="@+id/button5_date_arrive"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/button4"
    android:layout_marginLeft="50dp"
    android:text="Date2" />

<Button
    android:id="@+id/button6_time_arrive"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/button5_date_arrive"
    android:layout_marginLeft="70dp"
    android:text="Time2" />

<Button
    android:id="@+id/Button03"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/button6_time_arrive"
    android:gravity="center"
    android:text="Button" />

次に、ボタンの重力やマージンなどをいじることができます。これで問題が解決するはずです。

于 2013-08-12T15:18:08.647 に答える