1

У меня есть несколько элементов, расположенных в следующем порядке: textview, textview, ползунок, кнопка, gridview, кнопка, gridview, кнопка. Я переключаю вид сетки, когда нажимается кнопка над ней. Раньше я столкнулся с проблемой gridview, скрывающей все, что было ниже, и поэтому я назначил весы кнопкам, но gridview (хотя и прокручиваемый) выглядит очень смущенным. Как можно увеличить ширину GridView, так что элементы ниже, которые поддерживают их относительные позиции и появляются там, где они должны. (Я хочу, чтобы поведение расширяемого списка при нажатии на кнопку в основном)динамическое изменение в макете android

<TextView 
     android:id="@+id/text_view" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal|center_vertical" 
     android:layout_marginTop="20dip"   
     android:layout_marginLeft="10dip" 
     android:text="Select Price Range" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textSize="15sp" /> 


    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" >   
     <LinearLayout 
      android:id="@+id/seekBar_wrapper" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:layout_gravity="center_horizontal" 
      android:layout_marginTop="10dip" 
      android:padding="10dip" 
      /> 

     <RelativeLayout 
      android:id="@+id/absMinMax_holder" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:padding="10dip" 
      android:layout_weight="1" 
      > 
      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/absMinCarVal" 
       android:layout_alignParentLeft="true" 
       android:textSize="14sp" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/absMaxCarVal_above" 
       android:textSize="14sp" 
       android:layout_alignParentRight="true" /> 
     </RelativeLayout> 

     <RelativeLayout 
      android:id="@+id/minMax_holder" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="40dip" 
      android:paddingRight="40dip" 
      android:paddingTop="10dip" 
      android:paddingBottom="10dip" 
      > 
      <TextView 
       android:id="@+id/minVal" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/absMinCarVal" 
       android:layout_alignParentLeft="true" 
       android:textSize="18sp" /> 

      <TextView 
       android:id="@+id/value_seperator" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/value_seperator" 
       android:layout_centerHorizontal="true" 
       android:textSize="22sp" /> 

      <TextView 
       android:id="@+id/maxVal" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/absMaxCarVal" 
       android:textSize="18sp" 
       android:layout_alignParentRight="true" /> 
     </RelativeLayout> 
    </LinearLayout> 
<!-- <ScrollView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> --> 
     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:layout_weight="1" > 

      <Button 
       android:id="@+id/car_make" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Car Make" 
       android:gravity="left" 
       android:textSize="18sp" 
       android:layout_marginBottom="10dp"/> 


      <GridView 
       android:id="@+id/make_gridview" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:columnWidth="90dp" 
       android:numColumns="auto_fit" 
       android:verticalSpacing="10dp" 
       android:horizontalSpacing="10dp" 
       android:stretchMode="columnWidth" 
       android:gravity="center" 
       android:visibility="gone" 
       android:layout_weight="1" 
       android:layout_marginBottom="10dp"/>        

      <Button 
       android:id="@+id/car_models" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Car Models" 
       android:gravity="left" 
       android:textSize="18sp" 
       android:layout_marginBottom="20dp"/> 

      <GridView 
       android:id="@+id/models_gridview" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:columnWidth="90dp" 
       android:numColumns="auto_fit" 
       android:verticalSpacing="10dp" 
       android:horizontalSpacing="10dp" 
       android:stretchMode="columnWidth" 
       android:gravity="center" 
       android:visibility="gone" 
       android:layout_weight="1" 
       android:layout_marginBottom="10dp"/>   

     </LinearLayout> 
    <!-- </ScrollView> --> 
    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:text="Search" 
     android:textSize="18sp" /> 

ответ

0

Было бы проще использовать вместо этого tableLayout и создавать строки таблицы gone и visible при необходимости. Это даст эффект расширяемого списка. Пожалуйста, не стесняйтесь задавать любые вопросы

+0

Нет, это не поможет. У меня не может быть таблицы, поскольку мои данные не являются статическими. – Namratha

+0

Я реализовал его с динамическими данными. Вы можете создавать таблицу и добавлять данные программно – pvn

+0

Я сделал то же самое и имею код, но это может быть сложно переварить, так как у него есть некоторые другие функции, поэтому он не разместил его. Концепция проста и проста в реализации. У меня есть доступ к Db, и есть два расширяемых списка, из которых только 1 отображается в соответствии с выбором пользователя (radio btn), поэтому мой код немного длинный, поэтому я его не разместил – pvn

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