1

一部のビューを膨らませたいのですが、ビューの下部にボタンがあります。ビューを動的に膨らませてから、他の膨らませたビューの下にあるボタンを膨らませる方法をすでに知っています。ただし、膨らんだビューが数個しかない場合(結合されたビューのスペースが画面全体よりも少なくなるため)、ボタンはページの下部に表示されません。私の考えは、ボタンを次のように設定して、相対レイアウトの下部にボタンを配置する必要があるということです:android:layout_alignParentBottom(アプリがクラッシュしてもこれを実行しようとすると)

これが私が持っているもののスクリーンショットであり、続いて私が欲しいもののスクリーンショットがあります。あなたが見るすべてのアイテムは、相対的なレイアウトの内側にあるスクロールビューに膨らんでいます。問題は、ボタンがスクロールビューに膨らんでいることだと思います。スクロールビューは、アイテムがそれを強制するのと同じくらいの大きさです(残念ながら、ビューの別の部分に膨らませる方法を知るにはあまりにも初心者です)

ここに画像の説明を入力してください

左側の画像のコードは次のとおりです(左側のビューにはエラーがありません):parentView:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/blurybg"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">    
<ScrollView     
  android:layout_height="wrap_content" 
  android:id="@+id/scrollView1" 
  android:layout_width="fill_parent" >
<LinearLayout     
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id= "@+id/parent_of_inflated_view_id">
</LinearLayout>   
</ScrollView>
</RelativeLayout>

childButton(他のビューはこれに似ています)

<?xml version="1.0" encoding="utf-8"?>
<Button
xmlns:android="http://schemas.android.com/apk/res/android"
android:height="30dp"
android:layout_width="fill_parent"
android:background="@drawable/done"
android:layout_alignBottom ="@layout/availablerestaurants"
/>

インフレータを作成し、ボタンを膨らませるためのJava。他のインフレートビューはこれに似ています(もちろん同じインフレータを使用します)。膨らんだボタンを最後に追加して、ビューの下部に表示します。

LayoutInflater theInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
LinearLayout linLayout = (LinearLayout)findViewById(R.id.parent_of_inflated_view_id); 

    Button doneButtonCurrentRest=  (Button) theInflater.inflate(R.layout.done_button_availrest, null);
    linLayout.addView(doneButtonCurrentRest);

助けてくれてありがとう、アダム

4

1 に答える 1

1

私のコードを確認してください。意図したとおりに動作するはずです。

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

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/parent_of_inflated_view_id"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" />
    </ScrollView>

    <Button
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

あなたのコードはどうですか。私はいくつかの間違いを見ることができます:

1)android:layout_heightボタンに指定する必要があります。このパラメーターがないと、例外がスローされます。を使用しますandroid:heightが、 と同じではありませんandroid:layout_height

2) android:layout_alignBottomID を指す必要がありますが、レイアウトを指す必要はありません。さらに、ボタンの別のレイアウトでこの属性の目的がわかりません。

アップデート

以下のコメントの質問の解決策は次のとおりです。

<?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:fillViewport="true" >

    <LinearLayout
        android:id="@+id/layout_for_positioning"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/parent_of_inflated_view_id"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical" />

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_weight="0" />
    </LinearLayout>

</ScrollView>

android:fillViewport="true"画面全体を埋めることができるように、ScrollViewに使用したことに注意してください。また、ビューを適切に引き伸ばすために使用していました (ここandroid:layout_weightで属性の説明を見つけることができます )。

于 2012-08-31T13:23:52.953 に答える