2013-05-02 4 views
0

Я новичок в android.When я пытаюсь сделать экран прокручиваемым, экран становится прокручиваемым, но содержимое не отображается. Экран содержит список и другое табличное представление. Это код, который я использую.Как сделать экран со списком и таблицей прокрутки?

 <?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:layout_height="fill_parent" 
android:stretchColumns="1" 
android:scrollbars="vertical" 
android:isScrollContainer="true" 
android:scrollbarAlwaysDrawVerticalTrack="true"> 




    <TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout1" android:layout_width="fill_parent" android:layout_height="70dp" android:layout_marginRight="3dp" 
    > 
    <TableRow android:layout_width="wrap_content" android:layout_marginTop="5dp" > 
    <ImageView 
    android:id="@+id/logo" 
    android:layout_width="90dp" 
    android:layout_height="90dp" 
    android:src="@drawable/logo" 
    android:layout_marginLeft="3dp" 

    /> 
    <ImageView 
    android:id="@+id/back" 
    android:layout_width="30dp" 
    android:layout_height="40dp" 
    android:src="@drawable/back" 
    android:layout_marginLeft="20dp" 
    android:layout_marginTop="20dp" 
    /> 

    <ImageView 
     android:id="@+id/timesheet" 
     android:layout_width="90dp" 
     android:layout_height="70dp" 
     android:layout_marginLeft="20dp" 
     android:layout_marginTop="1dp" 
     android:src="@drawable/timesheet" /> 

    <ImageView 
    android:id="@+id/home" 
    android:layout_width="35dp" 
    android:layout_height="50dp" 
    android:src="@drawable/home" 
    android:layout_marginTop="17dp" 
    android:layout_marginLeft="25dp" 
    android:layout_marginRight="20dp" 

    /> 
    </TableRow> 

    </TableLayout> 


    <TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout1" android:layout_width="fill_parent" android:layout_height="40dp" android:layout_marginTop="70dp" android:layout_marginLeft="5dp" android:layout_marginRight="8dp" 
    > 

    <TableRow android:layout_width="70dp" android:layout_height="100dp" android:layout_marginTop="10dp" android:background="#000000" > 
     <TextView 
     android:text="Timesheets for Approval" 
     android:layout_width="wrap_content" 
     android:layout_height="80dp" 
     android:textSize="18dp" 
     android:layout_marginTop="3dp" 
     android:textColor="#ffff" 
     android:layout_marginLeft="70dp" 
     />  
    </TableRow> 
    </TableLayout> 


<ListView android:layout_width="wrap_content" 
    android:id="@+id/listView1" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="120dp" 
    android:layout_marginLeft="5dp" 
    android:layout_marginRight="8dp" 
      /> 

<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout1" android:layout_marginTop="415dp" android:layout_marginLeft="5dp" android:layout_marginRight="8dp" android:layout_width="400dp" android:layout_height="170dp" 
    android:stretchColumns="*" 
    android:background="@drawable/shape"> 

     <TableRow android:layout_width="fill_parent" android:layout_marginTop="2dp" android:layout_marginLeft="5dp" android:layout_marginRight="8dp" > 
      <TextView 
     android:text="Timesheet Details" 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     />  

     </TableRow> 

    <TableRow android:layout_width="fill_parent" android:layout_marginLeft="1dp"> 
     <TextView 
     android:text="Emp Name" 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="13dp" 

     />   
     <EditText android:text="EditText" android:id="@+id/emp_name" android:enabled="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="13dp" 
      ></EditText> 
     <EditText android:text="EditText" android:id="@+id/emp_code" android:enabled="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="13dp" 
      ></EditText> 
    </TableRow> 
    <TableRow android:layout_width="fill_parent" android:layout_marginLeft="1dp"> 

     <TextView 
     android:text="From Date" 
     android:id="@id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="13dp" 

     />   
     <EditText android:text="EditText" android:id="@+id/from_date" android:enabled="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="13dp" 
      ></EditText> 
    </TableRow> 
    <TableRow android:layout_width="fill_parent" android:layout_marginLeft="1dp"> 
     <TextView 
      android:text="To Date" 
      android:id="@id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="13dp" 

      />  
     <EditText android:text="EditText" android:id="@+id/to_date" android:enabled="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="13dp" 
      ></EditText> 
    </TableRow> 
    <TableRow android:layout_width="fill_parent" android:layout_marginLeft="1dp"> 
     <TextView 
      android:text="Target Hrs" 
      android:id="@id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="13dp" 

     /> 
      <EditText android:text="EditText" android:id="@+id/target_hours" android:enabled="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="13dp" 
       ></EditText> 
     <TextView 
      android:text="Actual Hrs" 
      android:id="@id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="13dp" 

      /> 
      <EditText android:text="EditText" android:id="@+id/actual_hours" android:enabled="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="13dp" 
       ></EditText> 
    </TableRow> 

</TableLayout> 
<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/tableLayout1" android:layout_marginTop="600dp" android:layout_marginLeft="1dp" android:layout_width="400dp" android:layout_height="wrap_content" 
    > 

    <TableRow android:layout_width="fill_parent" android:layout_marginLeft="1dp"> 
<Button android:id="@+id/approve" android:layout_width="wrap_content" android:layout_height="22dp" android:background = "@drawable/approve" android:textColor="#ffff" android:layout_marginLeft="30dp" ></Button> 
<Button android:id="@+id/reject" android:layout_width="wrap_content" android:layout_height="22dp" android:background = "@drawable/reject" android:textColor="#ffff" android:layout_marginLeft="50dp" android:layout_marginRight="20dp" ></Button> 
<Button android:id="@+id/detail" android:layout_width="wrap_content" android:layout_height="22dp" android:background = "@drawable/details" android:textColor="#ffff" android:layout_marginLeft="30dp" android:layout_marginRight="30dp"></Button> 

</TableRow> 

</TableLayout> 

</LinearLayout> 
</ScrollView> 
+0

Scrollview не работает, как ожидалось с ListView, потому что ListView уже содержит Scrollview –

+0

ListView представляет собой комплекс управления с некоторыми оптимизациями в прокрутке. если вы поместите его в scrollview, все оптимизации исчезнут! поэтому рассмотрите возможность изменения дизайна. – Mbt925

ответ

2

Вы можете добавить два верхних tablelayout списка вида как Header View из ListView и двух tablelayout ниже список как footer view из списка.

Что-то вроде этого:

Заголовок Вид:

ListView.addHeaderView(HeaderView); 

Footer Вид:

ListView.addFooterView(FooterView); 

Снимите scrollview. Теперь ваш макет будет прокручиваться со списком без scrollview.

+0

+1 для приятного ответа –

1

Вы не можете использовать ListView внутри ScrollView, если вы не внесете свой собственный Scrollview и не обработаете событие касания.

Я вижу, что вы хотите, чтобы вся страница была прокручиваемой, таким образом, когда вы прокручиваете вниз по таблице, в конечном итоге выйдете из экрана. Для этого вам необходимо:

  1. Удалить ScrollView.
  2. Поместите таблицу в другой XML-файл.
  3. Используйте метод addHeaderView(View v) в своем списке и добавьте таблицу в список.

    listview.addeaderView(tableView); 
    
0

Согласно направляющим линиям интерфейса и передовой практике, желательно не использовать Scrollable содержимого внутри Scrollview и делают, что предотвращает прокручивание прокрутки контента.

Когда вы помещаете два виджета с прокруткой, просто путайте, какой вид прокрутки коснулся. Поэтому иногда он не может доставить событие касания.

Но если вы хотите достичь прокрутки, вы можете управлять им, используя событие onTouch для определенного вида. И вам нужно соответствующим образом спроектировать ваш макет.

Но даже если требование заставляет вас делать такие макеты. Попробуйте это ...

Скажите, что это похоже на это ....

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context=".MainActivity" > 

<ScrollView 
    android:id="@+id/svssvMain" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alignParentTop="true" > 

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

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textColor="@android:color/black" 
      android:textSize="20sp" 
      android:layout_margin="10dp" 
      android:text="@string/tv_content"/> 
     <View 
      android:layout_width="fill_parent" 
      android:layout_height="1dp" 
      android:background="@android:color/black"/> 
     <ListView 
      android:id="@+id/svslvMain" 
      android:layout_width="fill_parent" 
      android:layout_height="100dp" 
      android:cacheColorHint="#00000000"/> 
     <View 
      android:layout_width="fill_parent" 
      android:layout_height="1dp" 
      android:background="@android:color/black"/> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textColor="@android:color/black" 
      android:textSize="20sp" 
      android:layout_margin="10dp" 
      android:text="@string/tv_content"/> 
     <View 
      android:layout_width="fill_parent" 
      android:layout_height="1dp" 
      android:background="@android:color/black"/> 
     <ScrollView 
      android:id="@+id/svssvchild" 
      android:layout_width="fill_parent" 
      android:layout_height="100dp"> 

      <TextView 
       android:id="@+id/svstvContent" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textSize="20sp" 
       android:layout_margin="10dp" 
       android:text="@string/lipsum"/> 
     </ScrollView> 
     <View 
      android:layout_width="fill_parent" 
      android:layout_height="1dp" 
      android:background="@android:color/black"/> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textColor="@android:color/black" 
      android:textSize="20sp" 
      android:layout_margin="10dp" 
      android:text="@string/tv_content"/> 
     <View 
      android:layout_width="fill_parent" 
      android:layout_height="1dp" 
      android:background="@android:color/black"/> 
     <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/android"/> 
    </LinearLayout> 
</ScrollView> 

Шаг 1: Предоставление уникального идентификатора как Scrollview.

Шаг 2: получить ссылку этого два Scrollview & ListView в вашей деятельности.

 m_lvMain = (ListView) findViewById(R.id.svslvMain); 
    m_svMain = (ScrollView) findViewById(R.id.svssvMain); 
    m_svchild = (ScrollView) findViewById(R.id.svssvchild); 

Шаг 3: Теперь Настр.сенс.экр слушателей для Listview и ScrollView.

m_svMain.setOnTouchListener(new View.OnTouchListener(){ 
     public boolean onTouch(View p_v, MotionEvent p_event) 
     { 
      // Log.v(TAG, "PARENT TOUCH"); 
     findViewById(R.id.svslvMain).getParent().requestDisallowInterceptTouchEvent(false); 
      findViewById(R.id.svssvchild).getParent().requestDisallowInterceptTouchEvent(false); 
      return false; 
     } 
    }); 
    m_svchild.setOnTouchListener(new View.OnTouchListener(){ 
     public boolean onTouch(View p_v, MotionEvent p_event) 
     { 
      // Log.v(TAG, "CHILD TOUCH"); 
      // Disallow the touch request for parent scroll on touch of 
      // child view 
      p_v.getParent().requestDisallowInterceptTouchEvent(true); 
      return false; 
     } 
    }); 
    m_lvMain.setOnTouchListener(new View.OnTouchListener(){ 
     public boolean onTouch(View p_v, MotionEvent p_event) 
     { 
      // Log.v(TAG, "CHILD TOUCH"); 
      // Disallow the touch request for parent scroll on touch of 
      // child view 
      p_v.getParent().requestDisallowInterceptTouchEvent(true); 
      return false; 
     } 
    }); 

Я надеюсь, что это поможет.

0

установить ориентацию вашей линейной компоновки на вертикальную.

android:orientation="vertical" 

и удалить

xmlns:android="http://schemas.android.com/apk/res/android" 

из других макетов, чем основной Scrollview.

Оберните свой списокView в другой линейный макет и укажите высоту для него. , когда вы используете Scrollview то почему добавление

android:stretchColumns="1" 
android:scrollbars="vertical" 
android:isScrollContainer="true" 
android:scrollbarAlwaysDrawVerticalTrack="true" 

к вашей линейной компоновке. измените LinearLayout как:

<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical"> 
Смежные вопросы