-3

У меня есть два вида прокрутки для двух разных макетов. И эти два макета находятся внутри линейного макета.Как использовать прокрутку в Android

Вот мой XML-файл. Я не знаю почему ScrollView не работает для меня

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

    <LinearLayout 
      android:id="@+id/flightResultData" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="8dp" 
      android:orientation="vertical" > 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal" > 

       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:orientation="horizontal" > 

        <LinearLayout 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:orientation="vertical" > 

         <ImageView 
          android:id="@+id/onewayflightLogo" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="3dp" 
          android:src="@drawable/spicejet" /> 

         <TextView 
          android:id="@+id/onewayflightName" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="SpiceJet" /> 

         <TextView 
          android:id="@+id/onewayflightNumber" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="9W - 496" /> 
        </LinearLayout> 

        <LinearLayout 
         android:layout_marginTop="8dp" 
         android:layout_width="fill_parent" 
         android:layout_height="match_parent" 
         android:orientation="vertical" > 

         <TextView 
          android:id="@+id/onewayflightTime" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="5dp" 
          android:minLines="1" 
          android:text="06:00 - 7:05" 
          android:textSize="12dp" /> 

         <TextView 
          android:id="@+id/onewayflightDuration" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="5dp" 
          android:minLines="1" 
          android:text="1h 35m | Non Stop" 
          android:textSize="10dp" /> 
         <TextView 
          android:id="@+id/onewayflightAmount" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="5dp" 
          android:minLines="1" 
          android:text="Rs 200000" 
          android:textSize="12dp" /> 
        </LinearLayout> 
       </LinearLayout> 
       <View 
        android:layout_width="1dp" 
        android:layout_height="60dp" 
        android:background="@android:color/darker_gray" /> 
       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:orientation="horizontal" > 

        <LinearLayout 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:orientation="vertical" > 

         <ImageView 
          android:id="@+id/retrunflightLogo" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="3dp" 
          android:src="@drawable/spicejet" /> 

         <TextView 
          android:id="@+id/retrunflightName" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="SpiceJet" /> 

         <TextView 
          android:id="@+id/retrunflightNumber" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="9W - 496" /> 
        </LinearLayout> 

        <LinearLayout 
         android:layout_marginTop="8dp" 
         android:layout_width="fill_parent" 
         android:layout_height="match_parent" 
         android:orientation="vertical" > 

         <TextView 
          android:id="@+id/retrunflightTime" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="5dp" 
          android:minLines="1" 
          android:text="06:00 - 7:05" 
          android:textSize="12dp" /> 

         <TextView 
          android:id="@+id/retrunflightDuration" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="5dp" 
          android:minLines="1" 
          android:text="1h 35m |Non Stop" 
          android:textSize="10dp" /> 

         <TextView 
          android:id="@+id/retrunflightAmount" 
          android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:layout_marginLeft="5dp" 
          android:minLines="1" 
          android:text="Rs 200000" 
          android:textSize="12dp" /> 
        </LinearLayout> 
       </LinearLayout> 
      </LinearLayout> 
     </LinearLayout> 
</LinearLayout> 

Это мой основной макет, в котором я накачивания мой выше XML динамически через петлю

<LinearLayout 
     android:id="@+id/flightResultData" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/sortFlightLayouts" 
     android:layout_marginLeft="8dp" 
     android:orientation="vertical" > 
</LinearLayout> 

И в моем коде деятельности я делаю это:

void setTestResultData(){ 

    flightResult=(LinearLayout)findViewById(R.id.flightResultData); 
    LinearLayout.LayoutParams flightDetailsLayout = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
    LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    LinearLayout.LayoutParams forUnderLine = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT); 
    forUnderLine.setMargins(0,0, 0, 0); 
    for(int i=0;i < 13;i++){ 
     LinearLayout flightInformations=(LinearLayout)inflater.inflate(R.layout.flight_details_layout, null); 
     flightResult.addView(flightInformations); 
    } 
} 
+0

Невозможно использовать listviews вместо этого? –

+0

@ AndroSelva no Мне нужно использовать линейные макеты см. Ссылку на изображение, которую я разместил, и будет легко понимать, что я должен делать – Developer

+0

@Gaurav использует listview, добавляя линейные макеты как верхний и нижний колонтитулы. Я предложил это раньше, и теперь я предлагаю это. На самом деле используйте gridview. добавьте верхний и нижний колонтитулы в gridview. Рекомендуем использовать gridview. – Raghunandan

ответ

0

если вы отображения Scrollview в горизонтальной Linear Layout и учитывая вес Scrollview затем установить ширину Scrollview в «0dp»

android:layout_width="0dp" 

и если она вертикальна, то

android:layout_height="0dp" 

также установить основную высоту LinearLayout заполнить родителю

+0

. Так что просто возьмите горизонтальный прокрутки –

+0

Мне нужно прокрутить прокрутку по вертикали и по макете – Developer

+0

Просто вставьте свой экран или поцарапайте ... так что мне будет легче понять и протестировать также –

1

Я думаю, что вам нужен простой, две колонки организации:

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

    <!-- stuff goes here that should appear above the scrolling areas --> 

    <ScrollView 
     android:id="@+id/left_side_scroller" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" > 

     <!-- contents of left side go here --> 
    </ScrollView> 

    <ScrollView 
     android:id="@+id/right_side_scroller" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" > 

     <!-- contents of right side go here --> 
    </ScrollView> 

    <!-- stuff goes here that should appear below the scrolling areas --> 
</LinearLayout> 

Альтернативно (и, возможно, лучше), похоже, что вы должны использовать два элемента ListView вместо двух ScrollView элементов. Каждый ListView будет иметь те же параметры компоновки, что и выше для ScrollView. Поскольку ListView управляет прокруткой внутри, вам тогда не нужно ScrollView.

Кроме того, вы, вероятно, хотите, чтобы весь макет заполнил экран, элементы «фильтр» и «сортировка» всегда были внизу. Для достижения этого эффекта макет верхнего уровня должен иметь android:layout_height="fill_parent" вместо "wrap_content". Кроме того, прокручиваемые области должны иметь android:layout_height="0dp" и ненулевой вес (что они уже делают).

+0

Я новичок в android может помочь мне для некоторого примера кода, как я могу использовать listview для моего дизайна, которые имеют два макета на левой и правой стороне. – Developer

+0

@Gaurav. Посмотрите на [справочный раздел «Просмотр списка»] (http: // разработчик .android.com/guide/themes/ui/layout/listview.html), чтобы узнать, как работает «ListView». Он научит вас, как сделать макет с помощью одного «ListView». (Однако вы не хотите «ListActivity», потому что он имеет дело только с одним «ListView». Поэтому не следуйте этой части руководства.) Затем просто замените два 'ListView' вместо 'ScrollView 's я имею в моем ответе. У вас будет макет, в котором есть два независимых прокручиваемых списка строк, которые вы хотите. Это немного сложно, но и ваши требования. –

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

  • Нет связанных вопросов^_^