0

私のアプリでは、スピナーのペアを、スクロールビュー内にあるlinearlayoutに挿入します。問題は、十分な数のスピナーを追加すると、上位2つが部分的に不明瞭になることです。これが私が話していることです。

:(

<LinearLayout
android:id="@+id/ChordHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:drawable/bottom_bar"
android:orientation="horizontal" >

<Button
    android:id="@+id/addChordButton"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:text="Add Chord" />

<TextView
    android:id="@+id/spacetext1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="  "
    android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
    android:id="@+id/removeChordButton"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:text="Remove Chord" />
 </LinearLayout>

 <ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >

<LinearLayout
    android:id="@+id/ChordList"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:isScrollContainer="true"
    android:orientation="vertical"
    android:weightSum="100" >

(スピナーはここに挿入されます)

</LinearLayout>
 </ScrollView>
 </LinearLayout>

問題が問題である場合は、スピナーをリストに挿入するコードを次に示します。

    Spinner chordName = new Spinner(this);
    Spinner chordType = new Spinner(this);

    LinearLayout container = new LinearLayout(this);
    container.setOrientation(LinearLayout.HORIZONTAL);
    LinearLayout chordList = (LinearLayout) findViewById(R.id.ChordList);

    chordName.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 80, 50));
    chordName.setAdapter(nameAdapter);
    container.addView(chordName); //add name spinner to container

    chordType.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 80, 50));
    chordType.setAdapter(typeAdapter);
    container.addView(chordType); //add type spinner to container
    container.setBackgroundResource(android.R.drawable.bottom_bar);
    container.setPadding(10, 0, 10, 0);


    chordList.addView(container); //add container to list layout
4

2 に答える 2

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

    <RelativeLayout
        android:id="@+id/ChordHeader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:drawable/bottom_bar">

        <Button
            android:id="@+id/addChordButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:text="Add Chord" />


        <Button
            android:id="@+id/removeChordButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:ellipsize="middle"
            android:text="Remove Chord" />

    </RelativeLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/ChordHeader"
        >

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

        </LinearLayout>
    </ScrollView>

</RelativeLayout>

ここで、ボタンについて、本当に同じサイズが必要な場合は、寸法を設定することをお勧めします。Androidでディメンションを保存する方法は次のとおりです:その他のリソースタイプ:ディメンション

于 2012-07-01T02:38:10.030 に答える
0

スピナーの追加が完了したら、リストの一番上のアイテムへの参照を取得し、それにフォーカスを要求してみてください。

chordList.getChildAt(0).requestFocus();
于 2012-07-01T02:06:23.373 に答える