0

嗨,我創建了一個普通的滾動視圖的表格佈局,我希望它滾動垂直和水平。在XML中,有可能或者有其他解決方案可以解決,因爲一旦超出了文本長度,我的文本將不再出現在表格中,並且會使表格佈局變大並移動到設備上。可以表格佈局同時具有水平和垂直滾動視圖

<ScrollView android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/linearImag"> 

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

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

     </LinearLayout> 

     <TableLayout 
      android:id="@+id/lead_table" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="20dp" 
      android:gravity="center" 
      android:stretchColumns="*" > 

      <TableRow 
       android:id="@+id/tableRow1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" > 

       <Button 
        android:id="@+id/textView2" 
        android:layout_width="wrap_content" 
        android:layout_height="25dp" 
        android:background="@drawable/bgbtn" 
        android:text="Lead ID" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textSize="20sp" /> 
     </TableLayout> 

     <Button 
      android:id="@+id/btn_add" 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:layout_marginLeft="25dp" 
      android:layout_marginTop="20dp" 
      android:background="@drawable/add" /> 

     <TextView 
      android:id="@+id/tv_data" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 
    </ScrollView> 

回答

1

而是正常的滾動視圖中,使用水平滾動視圖像

<Layout> 
<HorizontalScrollView 
     android:id="@+id/horizontalView" 
     android:layout_height="wrap_content"  
     android:scrollbars="horizontal|vertical" 
     android:layout_width="wrap_content"  
     android:layout_marginTop="5dip"> 
<TableLayout> 
    // child views... 
</TableLayout> 
</HorizontalScrollView> 
</Layout> 

希望這將解決您的問題:-)