0

У меня есть TableLayout в ScrollView. Мне нужно перейти к следующей LinearLayout (динамически созданной), которая находится внутри TableView, нажав кнопку закрытия и вернитесь к предыдущему LinearLayout, нажав кнопку «Назад».Как к следующему ребенку tablelayout android

Следуйте моим XML, как я создаю TableView:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:layout_weight="1"> 

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

     <android.support.v7.widget.Toolbar 
      android:id="@+id/tb_pergunta" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="?attr/colorPrimary" 
      android:minHeight="?attr/actionBarSize" /> 

     <ScrollView 
      android:id="@+id/sv_table" 
      android:layout_height="match_parent" 
      android:scrollbars="horizontal|vertical" 
      android:layout_width="match_parent" 
      android:layout_marginTop="5dip" 
      android:scrollbarStyle="outsideInset" 
      android:fillViewport="true"> 

     <TableLayout 
      android:id="@+id/tl_principal" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

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

<LinearLayout 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_weight="14"> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center_horizontal"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Ir para pergunta nº:" 
      android:id="@+id/btnProximaPergunta" 
      android:visibility="gone" /> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/botton_back" 
      android:id="@+id/btnBackGroupExpandable" /> 

     <EditText 
      android:layout_width="99dp" 
      android:layout_height="wrap_content" 
      android:inputType="number" 
      android:ems="10" 
      android:id="@+id/edtProximaPergunta" 
      android:textAlignment="center" /> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/botton_next" 
      android:id="@+id/btnNextGroupExpandable" /> 

    </LinearLayout> 
</LinearLayout> 

Как я могу это сделать?

+0

Лучше использовать фрагмент –

+0

Я не понял. Использовать фрагмент лучше? Быстро У вас есть примеры? Спасибо за прослушивание. – WilkeGutierre

ответ

0

Вы можете дать каждому LinearLayout произвольно сгенерированный идентификатор, как описано here.

Сохраните эти идентификаторы в массиве, а затем вы можете легко вызвать любой из них в любом порядке.

+0

Хорошо. Но как я это делаю для ScrollView, поставьте его наверху? Ибо, когда вы нажимаете кнопку, я хочу открыть ее. Сделайте это, не найденное в ScrollView. – WilkeGutierre

+0

// получить верхнюю позицию относительно родителя int top = tl_principal.getTop(); // перейдите к этой верхней позиции, обернув ScrollView myScrollLayout.scrollTo (0, вверху); – WilkeGutierre

+0

см. Здесь: http://stackoverflow.com/questions/6261958/android-how-to-scroll-scrollview-in-top – SoroushA

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