문제

I'm writing a small application for my nexus 7 tablet, and I have a strange error. To my understanding the following xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical" >
  <ScrollView>
    <TableRow
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:padding="2dip">
      <EditText
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:hint="name"
      android:inputType="text"
      android:textSize="20sp"/>
      <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textSize="20sp"
      android:text="smells more like prey than a hunter."/>
    </TableRow>
    <TableRow
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:padding="2dip">
      <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textSize="20sp"
      android:text="The spirits spoke to me of a great danger that follows"/>
      <EditText
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:hint="name"
      android:inputType="text"
      android:textSize="20sp"/>
    </TableRow>
  </ScrollView> 

</TableLayout>

should produce a scrollable app with two lines, each with a text field with gray name written in it, with the text wrap around it and additional text that will be written before or after the text that will try and fill the screen. When I compile this, however, the application crash (unfortunately, has stopped). If I remove the ScrollView attribute, The two lines are of the same length, with the EditText taking half the space on each line while in landscape mode. In portrait mode, the first line holds only the EditText field and the second one only the TextView field. It seams to me that the table tries to fit the two lines into the same length, but I can't understand why.

How can I fix this? Comment:
I'm using a library structure generate by aide, which I use only to compile my code on the tablet.

도움이 되었습니까?

해결책

put your table layout all inside the scrollview. scrollview can onlyhost one direct child, but that child can have many children! also you still need a height and width for scrollview

here

<?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 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="vertical" >
    <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="vertical" >
      <EditText
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:hint="name"
      android:inputType="text"
      android:textSize="20sp"/>
      <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
        android:gravity="center"
      android:textSize="20sp"
      android:text="smells more like prey than a hunter."/>
    </LinearLayout>
  <LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:orientation="vertical" >
   <EditText
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:hint="name"
      android:inputType="text"
      android:textSize="20sp"/>

      <TextView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:textSize="20sp"
      android:gravity="center"
      android:text="The spirits spoke to me of a great danger that follows"/>

  </LinearLayout>

</TableLayout>
</ScrollView>  

should work for u.

try the above layout instead of yours and let me know if it helps. to tell the truth i think you want a listview and an adapter...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top