4

我需要在相對佈局內執行滾動視圖。RelativeLayout中的滾動視圖

當我加入了滾動,這是結果http://postimg.org/image/6abxth299/其中組件只佔用了一半的屏幕,並打開該屏幕時,鍵盤默認

<?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" 
    android:scrollbars="vertical" > 
    <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" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     tools:context=".MainActivity" 
     android:layout_centerHorizontal="true" 
     android:id="@+id/data_entry_layout"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Post Title" 
       android:id="@+id/post_title" 
       android:layout_alignBaseline="@+id/post_title_input" 
       android:layout_alignBottom="@+id/post_title_input" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:textSize="26px"/> 

      <EditText 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/post_title_input" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentEnd="true" 
       android:layout_toRightOf="@+id/post_title" 
       android:layout_toEndOf="@+id/post_title" 
       android:inputType="textCapSentences"/> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Post Description" 
       android:id="@+id/post_description" 
       android:layout_below="@+id/post_title_input" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_marginTop="39dp" 
       android:textSize="26px"/> 

      <EditText 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="textMultiLine|textCapSentences" 
       android:ems="10" 
       android:id="@+id/editText" 
       android:layout_marginTop="16dp" 
       android:layout_below="@+id/post_description" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true"/> 

      <ImageButton 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:id="@+id/imageButton1" 
       android:layout_below="@+id/editText" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:baselineAlignBottom="false" 
       android:contextClickable="true" 
       android:src="@drawable/image_button_icon" 
       android:onClick="galleryIntent"/> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Cancel" 
       android:id="@+id/cancel" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_below="@id/imageButton1" 

       /> 

      <Button 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Submit" 
       android:id="@+id/submit" 
       android:layout_alignTop="@+id/cancel" 
       android:layout_alignParentRight="true" 
       android:layout_alignParentEnd="true" 
       android:layout_below="@id/imageButton1"/> 

    </RelativeLayout> 
</ScrollView> 
+0

未來切勿使用'match_parent'作爲高度的RelativeLayout時,滾動型中,將其更改爲'wrap_content'。 –

+0

然而,它仍然佔據屏幕的一半 – cgeekmt

+0

你想要什麼? –

回答

0

嘗試在此活動去除鍵盤添加下面的AndroidManifest默認情況下出現

android:windowSoftInputMode="stateAlwaysHidden|adjustResize" 

和使用android:layout_height="wrap_content"了滾動,sugesting使用的LinearLayout垂直方向佈局參見有用的。

+0

你試過這個嗎?@cgeekmt –

+0

是的這適用於鍵盤。謝謝! – cgeekmt

1

第一的高度上來滾動視圖的子目錄,相對或線性佈局應該是包裝內容和不匹配父項。此外,內部孩子應該具有特定的體重或身高,並且不像父母爲imageButton所做的那樣匹配父母。

+0

將高度更改爲430px並且它可以工作。但是,我認爲它不會對其他設備做出響應。 (即高度不會相應調整)? – cgeekmt

+0

哪個高度變爲430px? –

+0

的imagebutton cgeekmt

0

我認爲ScrollView在Relativelayout中不起作用。最好使用LinearLayout。

0

試試這個...

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

    <RelativeLayout 
     android:id="@+id/data_entry_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_centerHorizontal="true" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin"> 
     <RelativeLayout 
      android:id="@+id/Rel12345" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 

     <TextView 
      android:id="@+id/post_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignBaseline="@+id/post_title_input" 
      android:layout_alignBottom="@+id/post_title_input" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:text="Post Title" 
      android:textSize="26px" /> 

     <EditText 
      android:id="@+id/post_title_input" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentEnd="true" 
      android:layout_alignParentRight="true" 
      android:layout_toEndOf="@+id/post_title" 
      android:layout_toRightOf="@+id/post_title" 
      android:inputType="textCapSentences" /> 

     <TextView 
      android:id="@+id/post_description" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_below="@+id/post_title_input" 
      android:layout_marginTop="39dp" 
      android:text="Post Description" 
      android:textSize="26px" /> 

     <EditText 
      android:id="@+id/editText" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_below="@+id/post_description" 
      android:layout_marginTop="16dp" 
      android:ems="10" 
      android:inputType="textMultiLine|textCapSentences" /> 

     <ImageButton 
      android:id="@+id/imageButton1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" 
      android:layout_below="@+id/editText" 
      android:baselineAlignBottom="false" 
      android:contextClickable="true" 
      android:onClick="galleryIntent" 
      /> 
     </RelativeLayout> 

     <RelativeLayout 
      android:id="@+id/Rel1234" 
      android:layout_below="@id/Rel12345" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true"> 

      <Button 
       android:id="@+id/cancel" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:text="Cancel"/> 

      <Button 
       android:id="@+id/submit" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentEnd="true" 
       android:layout_alignParentRight="true" 
       android:layout_alignTop="@+id/cancel" 
       android:text="Submit" /> 
     </RelativeLayout> 
    </RelativeLayout> 
</ScrollView> 

,並嘗試添加下面的AndroidManifes去除鍵盤默認

android:windowSoftInputMode="stateAlwaysHidden|adjustResize" 
+0

@cgeekmt這一個是你的問題的測試完整的解決方案 –

相關問題