2014-02-07 31 views
0

這裏是我的xml代碼,我想在View中應用滾動但在設備屏幕中沒有出現滾動。這裏是XML佈局。有人請告訴我可能的解決方案來克服這種情況.....無法使用Android在設備S3中滾動?

<?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:background="@drawable/home_bg" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 
     <LinearLayout 
      android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 

     <ImageView 
      android:id="@+id/askfatwa_header" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/askfatwa_top_bar" /> 
</LinearLayout> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/askfatwa_header" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="5dp" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/name_askscreen" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/name" 
       android:textColor="@android:color/white" 
       android:textSize="20sp" /> 

      <EditText 
       android:id="@+id/askscreen_name" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="3dp" 
       android:paddingLeft="5dp" 
       android:maxLines="1" 
       android:inputType="text" 

       android:background="@drawable/textfield" > 
      </EditText> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="5dp" 
      android:orientation="vertical" > 

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

       android:text="@string/Email" 
       android:textColor="@android:color/white" 
       android:textSize="20sp" /> 

      <EditText 
       android:id="@+id/askscreen_email" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="3dp" 
       android:maxLines="1" 
       android:inputType="textEmailAddress" 
        android:background="@drawable/textfield" 
       android:paddingLeft="5dp" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="5dp" 
      android:orientation="vertical" > 

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

       android:text="@string/Address" 
       android:textColor="@android:color/white" 
       android:textSize="20sp" /> 

      <EditText 
       android:id="@+id/askscreen_address" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="3dp" 
       android:paddingLeft="5dp" 
       android:inputType="textMultiLine" 

       android:background="@drawable/textfield" /> 
     </LinearLayout> 
     <!-- <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="5dp" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/contact_askscreen" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/Contact" 
       android:textColor="@android:color/white" 
       android:textSize="20sp" /> 

      <EditText 
       android:id="@+id/askscreen_contact" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="3dp" 
       android:paddingLeft="5dp" 
        android:background="@drawable/textfield" /> 
     </LinearLayout> --> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="5dp" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/subject_askscreen" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/Subject" 
       android:textColor="@android:color/white" 
       android:textSize="20sp" /> 

      <!-- <EditText 
       android:id="@+id/askscreen_subject" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="3dp" 
       android:paddingLeft="5dp" /> --> 
       <Spinner 
       android:id="@+id/askscreen_subject" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="3dp" 
       android:paddingLeft="5dp"/> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="15dp" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="5dp" 
      android:orientation="vertical" > 

      <!-- <TextView 
       android:id="@+id/body_askscreen" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:hint="Type Your Question" 
       android:textColor="@android:color/white" 
       android:textSize="20sp" /> --> 

      <EditText 
       android:id="@+id/askscreen_question" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="3dp" 
       android:background="@drawable/textfield" 
       android:hint="Type Your Question" 
       android:minLines="1" 
       android:inputType="textMultiLine" 
       android:minHeight="8dp" 
       android:minWidth="10dp" 
       android:lines="15" 
       android:paddingLeft="5dp" /> 

     </LinearLayout> 


     <ImageView 
      android:id="@+id/askscreen_submit_btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_marginTop="10dp" 
      android:paddingTop="20dp" 
      android:src="@drawable/askftwa_submit_button" /> 
    </LinearLayout> 

</ScrollView> 
+0

你有很多不必要的LinearLayouts的,你應該儘量讓這個打火機,對於表演和可讀性的緣故.. – 2Dee

+0

@ 2Dee能不能請你編輯代碼並在這裏寫出正確的代碼 – user3233280

+0

我可以但我寧願你自己嘗試糾正它,然後問你是否有問題,否則你不會學習。 「給一個人一條魚,你喂他一天,教一個人去釣魚,你一輩子喂他。」嘗試遵循Lint警告,例如,您的IDE應該強調包含askfatwa_header的LinearLayout完全無用的事實,因爲它只有一個孩子。如果你真的想要你的代碼審查,請嘗試http://codereview.stackexchange.com/ – 2Dee

回答

0

添加更多元素並出現滾動條。現在所有的元素都在屏幕內裝修,這就是爲什麼你看不到任何滾動

+0

沒有當我的鍵盤出現我的文本框之一是隱藏的,它不滾動 – user3233280

+0

@ user3233280嘗試添加屬性'android:windowSoftInputMode =「adjustResize」 '在清單 – JoelFernandes

+0

仍然不能正常工作 – user3233280

0
First a fall by seeing your xml, you are creating very expensive layout containing 
unnecessarily many Linear layouts ie when orientation of your all views are vertical.  
Why are you defining your views like textbox and edittext in separate Linear Layouts, 
it creates performance issues. 

Secondly, you should not define set any background and orientation in scroll view. 
By default orientation of scroll view is vertical. 

Although i just run your code with few changes and its working fine on my emulator 
and on my device. 



<?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" > 

    // This is Main layout which contains all your child view 

    <LinearLayout 
     android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/home_bg" 
    android:orientation="vertical" > 

    // Define your remaining child views here..... 
    // And as i can see all views are oriented vertically, so you can define all view 
     inside this Main Layout itself. 
    // Accordingly you can set Margins of your views too. 


    </LinearLayout> 

</ScrollView> 
+0

可以請你檢查是否可以用圖像仍然不滾動我提供你的圖像 – user3233280

+0

你是否嘗試過在你的xml中插入更多的視圖。爲什麼不在你的xml中添加更多的圖像視圖?你將definetly要知道,你的佈局是否滾動或不...... –

+0

是的,我已經插入更多的視圖,但它不滾動,而相同的代碼,我已經插入其他地方這是滾動 – user3233280