1

layout.xmlに次のコードがあります。

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent">

    <EditText android:hint="@string/feed_url"
        android:id="@+id/feedUrl" android:textSize="14dp" android:inputType="textUri"
        android:layout_marginRight="45dp" android:layout_height="wrap_content" android:layout_width="fill_parent">
    </EditText>

    <Button android:id="@+id/getGraph"
        android:text="@string/get"
        android:layout_toRightOf="@id/feedUrl" 
        android:layout_alignParentRight="true"          
        android:layout_height="wrap_content" android:width="45dp" android:layout_width="wrap_content">
    </Button>

</RelativeLayout>

<WebView android:id="@+id/wv1" android:layout_height="wrap_content"
    android:layout_width="fill_parent" />
</LinearLayout>

Eclipseプラグインレイアウトクリエーターでは、EditTextとボタンが正しく表示されます。(下のスクリーンショットを参照)

代替テキスト

ただし、デバイスとエミュレーターでは、ボタンは非表示になりません。(下のスクリーンショットを参照)

代替テキスト

ボタンがデバイスに隠されている理由はありますか?

4

3 に答える 3

6

コードに次の変更を加えてみてください。ボタンは固定幅であるため、最初にボタンを定義してから、ボタンの左側に配置された残りのスペースを埋めるためにEditTextを配置する必要があります。ボタンも最初に定義する必要があります(つまり、Android 2.2より前)。

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent">

    <Button 
        android:id="@+id/getGraph"
        android:text="@string/get" 
        android:layout_alignParentRight="true"          
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content"
        />
    <EditText 
        android:hint="@string/feed_url"
        android:id="@+id/feedUrl" 
        android:textSize="14dp" 
        android:inputType="textUri"
        android:layout_marginRight="45dp" 
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent"
        android:layout_toLeftOf="@id/getGraph" 
        />
</RelativeLayout>
于 2010-10-15T12:46:42.337 に答える
0

EditTextレイアウトビルダーにボタンが表示されません...理由は、幅が親を塗りつぶしているため、ボタンを押し出すと親が塗りつぶされるためだと思います。を使用RelativeLayoutする必要がある場合は、幅をEditText明示的に定義する必要があります。それ以外の場合は、水平に切り替えてLinearLayout、編集ボックスの太さを「1」に設定することをお勧めします。

また、以下には無効なオプションがありますRelativeLayout

xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal
于 2010-10-15T11:57:46.470 に答える
0

これをアーカイブするために、RelativeLayoutの代わりにLinearLayoutを使用することもできます。android:layout_weightButtonをEditTextでオーバーレイしないようにするために使用できます。以下は、機能する可能性のあるサンプルxmlです。

<LinearLayout android:orientation="horizontal"
    android:layout_height="wrap_content" android:layout_width="fill_parent">
    <EditText android:hint="@string/feed_url"
        android:id="@+id/feedUrl" android:textSize="14dp"
        android:inputType="textUri" android:layout_marginRight="45dp"
        android:layout_height="wrap_content" android:layout_width="fill_parent" />
    <Button android:id="@+id/getGraph" android:text="@string/get"       
        android:layout_height="wrap_content" android:width="45dp"
        android:layout_width="wrap_content"
        android:layout_weight="1" />
</LinearLayout>
于 2010-10-15T13:30:36.243 に答える