2014-08-27 3 views
2

У меня есть ScrollView с LinearLayout и внутри 4 ImageView, но первый не показан.Первый встроенный ImageView в ScrollView не показан

(Имена вводимого коэффициента и идентификаторами являются не то же самое, я написал XXX намеренно)

Это мой макет

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linLayoutAbout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:orientation="vertical" > 


    // Another stuff 
    ... 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginBottom="5dp" 
     android:orientation="vertical" > 

     <ScrollView 
      android:id="@+id/scrollView1" 
      android:layout_width="wrap_content" 
      android:layout_height="65dp" 
      android:layout_gravity="center" 
      android:isScrollContainer="true" > 
      <LinearLayout 
       android:id="@+id/linLayoutScrollView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:orientation="vertical" >  

       <ImageView    //<- Just this ImageView is not shown 
        android:id="@+id/logo_XXX" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_marginBottom="5dp" 
        android:src="@drawable/logo_XXX" /> 

       <ImageView 
         android:id="@+id/logo_XXX" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:layout_marginBottom="5dp" 
         android:src="@drawable/logo_XXX" /> 

       <ImageView 
        android:id="@+id/logo_XXX" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_marginBottom="5dp" 
        android:src="@drawable/logo_XXX" /> 

       <ImageView 
        android:id="@+id/logo_XXX" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:src="@drawable/logo_XXX" /> 
      </LinearLayout>           
     </ScrollView> 
    </LinearLayout> 


    <Button 
     android:id="@+id/close_button" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="10dp" 
     android:text="@string/close_about" /> 

Если установить android:layout_height с некоторыми dp_value то я могу Я вижу первый ImageView, но если я установил его с помощью «wrap_content», тогда я могу увидеть все ImageView.

Может кто-нибудь сказать мне, что я делаю неправильно, и как я могу его решить?

Заранее спасибо.

ответ

3

Вы должны удалить строку

android:layout_gravity="center" 

в LinearLayout с идентификатором "@ + код/​​linLayoutScrollView1" внутри ScrollView. Поскольку он центрирует линейную компоновку в пределах этих 65 пикселей ScrollView, это означает, что половина изображений выше вышла из экрана.

Пробуйте этот код;

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linLayoutAbout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:orientation="vertical" > 
    // Another stuff 
    ... 


    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:layout_marginBottom="5dp" 
     android:orientation="vertical" > 

     <ScrollView 
      android:id="@+id/scrollView1" 
      android:layout_width="wrap_content" 
      android:layout_height="65dp" 
      android:layout_gravity="center" 
      android:isScrollContainer="true" > 

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

       <ImageView 
        android:id="@+id/logo_XXX1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_marginBottom="5dp" 
        android:src="@drawable/ic_launcher" /> 

       <ImageView 
        android:id="@+id/logo_XXX2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_marginBottom="5dp" 
        android:src="@drawable/ic_launcher" /> 

       <ImageView 
        android:id="@+id/logo_XXX3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:layout_marginBottom="5dp" 
        android:src="@drawable/ic_launcher" /> 

       <ImageView 
        android:id="@+id/logo_XXX4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:src="@drawable/ic_launcher" /> 
      </LinearLayout> 
     </ScrollView> 
    </LinearLayout> 

    <Button 
     android:id="@+id/close_button" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="10dp" 
     android:text="close_about" /> 

</LinearLayout> 

Я изменил это LinearLayout и добавил некоторые реальные значения изображениям. Теперь все изображения отображаются правильно. Просто замените ваши изображения и посмотрите на разницу.

+0

Это не сработало. Я пробовал все возможные комбинации с гравитацией и без гравитации в scrollview и LinearLayout. –

+0

Посмотрите мои изменения. –

+0

Он уже работал с первым ответом (перед редактированием), я запустил старый. Thx;) Но большое спасибо, что вы сделали такой пример. –

1

65 должно быть меньше общей высоты. Он должен показывать, когда вы пытаетесь увеличить значение dp, возможно, 150 и т. Д. Он работал с некоторыми случайными изображениями, которые я пробовал.

+0

Я тестирую сейчас, thx –

+0

Я получил низкую половину первого ImageView. Мое намерение с этим «65dp» состояло в создании прокручиваемого «окна» (ScrollView с определенной высотой), на котором я могу показать iamges. Если я увеличиваю высоту, я, конечно, покажу первый ImageView (как сказано), но я хочу прокрутить и просмотреть изображения над этим «окном». С уважением –

+1

Это было неважно, это была «гравитация» LinearLayour. Thx –

Смежные вопросы