2012-07-01 4 views
0

В моем приложении я вставляю пары прядильщиков в линейный режим, который находится внутри прокрутки. Проблема в том, что, когда я добавляю достаточно прядильщиков, две верхние части частично скрыты. Вот что я говорю.Вид сверху в LinearLayout, встроенный в ScrollView, только наполовину видимый

:(

<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 
+0

Я не понимаю вопроса ... вы вкладываете слишком много, чтобы соответствовать. Прокрутите так, чтобы отображались те, которые вы хотите. Что еще вы ожидаете от этого? – Barak

+0

thats, потому что вы устанавливаете высоту прокрутки в «match_parent» вместо «wrap_content» ... и точно так же, как комментарий .. не очень хорошая идея иметь «пустой» textView просто оставить некоторое пространство между двумя элементами try используя атрибут Gravity. – Raykud

+0

Барак, он не прокручивается дальше. –

ответ

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> 

Теперь для кнопок вы можете захотеть установить DIMEN, если вы действительно хотите, чтобы они один и тот же размер. Вот как сохранить размеры в Android: More Resource Types: Dimension

+0

Отлично. Спасибо. –

0

Попробуйте получить ссылку на верхний элемент в списке, а затем запросить фокус на нем, после того, как вы закончите добавление блесны.

chordList.getChildAt(0).requestFocus(); 
Смежные вопросы