2012-10-29 35 views
9

Tôi có một bố trí với scrollview:scrollview theo cả hai hướng android

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    android:fadingEdge="none" 
    android:overScrollMode="never" 
    > 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:weightSum="100" 
    android:background="@color/antiquewhite"> 
     <LinearLayout 
     android:id="@+id/top_layou" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:orientation="vertical" 
     android:layout_weight="15" 
     android:layout_marginLeft="40dp" 
     android:layout_marginRight="40dp" 
     android:layout_marginTop="25dp" 
     android:background="@color/bisque"> 

     <TextView 
      android:id="@+id/title_text_view" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="70dp" 
      android:layout_marginTop="15dp" 
      android:text="@string/user_information_text" 
      android:textSize="26dp" 
      android:textStyle="bold" 
      android:textColor="@color/black" /> 

     <TextView 
      android:id="@+id/subtitle_text_view" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="70dp" 
      android:layout_marginTop="5dp" 
      android:text="@string/user_information_subtitle_text" 
      android:textSize="20dp" 
      android:textStyle="bold" 
      android:textColor="@color/black"/> 

    </LinearLayout> 

     <LinearLayout 
      android:id="@+id/body_view" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="85" 
      android:orientation="horizontal" 
      android:layout_marginLeft="40dp" 
      android:layout_marginRight="40dp" 
      android:weightSum="100" 
      > 

      <LinearLayout 
       android:id="@+id/left_part" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
       android:layout_weight="50" 
       android:weightSum="100" 
       android:background="@color/antiquewhiter"> 

       <TextView 
        android:id="@+id/first_name_text_view" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="70dp" 
        android:layout_marginTop="30dp" 
        android:text="@string/first_name_text" 
        style="@style/bold_text18" 
        /> 

       <LinearLayout 
        android:id="@+id/first_name_edit_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:weightSum="100"> 

     <EditText 
      android:id="@+id/first_name_edit_text" 
      style="@style/editTextsvCard" 
      android:layout_marginLeft="70dp" 
      android:layout_marginTop="5dp" 
      android:layout_weight="90" 
      android:ems="10" 


      > 

     </EditText> 

       </LinearLayout> 

       <TextView 
        android:id="@+id/company_text_view" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="70dp" 
        android:layout_marginTop="30dp" 
        android:text="@string/company_text" 
        style="@style/bold_text18" /> 
       <LinearLayout 
        android:id="@+id/company_edit_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:weightSum="100"> 

     <EditText 
      android:id="@+id/company_edit_text" 
      style="@style/editTextsvCard" 
      android:layout_marginLeft="70dp" 
      android:layout_marginTop="5dp" 
      android:layout_weight="90" 
      android:ems="10" 
      > 

     </EditText> 

       </LinearLayout> 
           <TextView 
        android:id="@+id/phone_text_view" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="70dp" 
        android:layout_marginTop="30dp" 
        android:text="@string/phone_text" 
        style="@style/bold_text18"/> 
       <LinearLayout 
        android:id="@+id/phone_edit_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:weightSum="100"> 

     <EditText 
      android:id="@+id/phone_edit_text" 
      style="@style/editTextsvCard" 
      android:layout_marginLeft="70dp" 
      android:layout_marginTop="5dp" 
      android:layout_weight="90" 
      android:ems="10" 
      android:inputType="phone" 
      > 

     </EditText> 

       </LinearLayout> 

          <TextView 
        android:id="@+id/e_mail_text_view" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="70dp" 
        android:layout_marginTop="30dp" 
        android:text="@string/e_mail_text" 
        style="@style/bold_text18" /> 
       <LinearLayout 
        android:id="@+id/e_mail_edit_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:weightSum="100"> 

     <EditText 
      android:id="@+id/e_mail_edit_text" 
      style="@style/editTextsvCard" 
      android:layout_marginLeft="70dp" 
      android:layout_marginTop="5dp" 
      android:layout_weight="90" 
      android:ems="10" 
      android:inputType="textEmailAddress" 
      > 

     </EditText> 

       </LinearLayout> 

          <TextView 
        android:id="@+id/mobile_text_view" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="70dp" 
        android:layout_marginTop="30dp" 
        android:text="@string/mobile_text" 
        style="@style/bold_text18"/> 
       <LinearLayout 
        android:id="@+id/mobile_edit_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:weightSum="100"> 

     <EditText 
      android:id="@+id/mobile_edit_text" 
      android:layout_marginLeft="70dp" 
      android:layout_marginTop="5dp" 
      style="@style/editTextsvCard" 
      android:layout_weight="90" 
      android:ems="10" 

      > 

     </EditText> 

       </LinearLayout> 
      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/right_part" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="50" 
       android:paddingRight="40dp" 
       android:orientation="vertical" 
       android:weightSum="100" 
       android:background="@color/antiquewhiter"> 

       <TextView 
        android:id="@+id/last_name_text_view" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="70dp" 
        android:layout_marginTop="30dp" 
        android:text="@string/last_name_text" 
        style="@style/bold_text18" /> 
        <LinearLayout 
        android:id="@+id/last_name_edit_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:weightSum="100"> 

     <EditText 
      android:id="@+id/last_name_edit_text" 
      android:layout_marginLeft="70dp" 
      android:layout_marginTop="5dp" 
      android:layout_weight="100" 
      android:ems="10" 
      style="@style/editTextsvCard" 
      > 

     </EditText> 

       </LinearLayout> 

       <TextView 
        android:id="@+id/position_text_view" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="70dp" 
        android:layout_marginTop="30dp" 
        android:text="@string/position_text" 
        style="@style/bold_text18"/> 
        <LinearLayout 
        android:id="@+id/position_edit_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:weightSum="100"> 

     <EditText 
      android:id="@+id/position_edit_text" 
      android:layout_marginLeft="70dp" 
      android:layout_marginTop="5dp" 
      android:layout_weight="100" 
      android:ems="10" 
      style="@style/editTextsvCard" 
      > 

     </EditText> 

       </LinearLayout> 

        <TextView 
        android:id="@+id/fax_text_view" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="70dp" 
        android:layout_marginTop="30dp" 
        android:text="@string/fax_text" 
        style="@style/bold_text18"/> 
        <LinearLayout 
        android:id="@+id/fax_edit_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:weightSum="100"> 

     <EditText 
      android:id="@+id/fax_edit_text" 
      android:layout_marginLeft="70dp" 
      android:layout_marginTop="5dp" 
      android:layout_weight="100" 
      android:ems="10" 
      android:inputType="phone" 
      style="@style/editTextsvCard" 
      > 

     </EditText> 

       </LinearLayout> 

        <TextView 
        android:id="@+id/internet_text_view" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="70dp" 
        android:layout_marginTop="30dp" 
        android:text="@string/internet_text" 
        style="@style/bold_text18"/> 
        <LinearLayout 
        android:id="@+id/internet_edit_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:weightSum="100"> 

     <EditText 
      android:id="@+id/internet_edit_text" 
      android:layout_marginLeft="70dp" 
      android:layout_marginTop="5dp" 
      android:layout_weight="100" 
      android:ems="10" 
      style="@style/editTextsvCard" 
      > 

     </EditText> 

       </LinearLayout> 
            <TextView 
        android:id="@+id/b_text_view" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="70dp" 
        android:layout_marginTop="30dp" 
        android:text="@string/internet_text" 
        style="@style/bold_text18" 
        android:visibility="invisible" 
        /> 

        <LinearLayout 
        android:id="@+id/button_edit_layout" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:weightSum="100" 
        android:layout_gravity="right" 
        android:gravity="right"> 


     <Button 
      android:id="@+id/speichern_button" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="5dp" 
      android:layout_marginLeft="70dp" 
      android:layout_weight="40" 
      android:text="@string/speichern_text" 
      > 


     </Button> 

       </LinearLayout> 

      </LinearLayout> 

     </LinearLayout> 

</LinearLayout> 
</ScrollView> 

xem việc Vertical hoàn hảo nhưng tôi muốn biết nếu tôi có thể thêm cuộn ngang để bố trí này bởi vì khi tôi có bố trí định hướng ngang có vẻ tốt nhưng khi tôi thay đổi hướng tôi không muốn giảm kích thước một số yếu tố trong bố cục. Tôi nghĩ về việc thêm scrool ngang. Điều này là khả thi?

Trả lời

7

tôi thêm:

<HorizontalScrollView 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fillViewport="true" 
> 

như con xem di chuyển của tôi và giải pháp này hoạt động tuyệt vời.

+13

Tính năng này hoạt động nhưng chỉ một trong số ScrollView hoạt động cùng một lúc. Ý tôi là bạn không thể cuộn theo đường chéo. – szedjani

Các vấn đề liên quan