0

當手機處於肖像模式時,它會在頂部和底部顯示標題和圖片,其中包含按鈕和註釋。但是,當我將手機設爲橫向模式時,按鈕和ListView消失,只顯示標題和圖像。我基本上不能在圖像下面滾動。更改方向將刪除用戶界面元素

還有第三個元素 - 一個TextView爲身體 - 這也是在ScrollView:每個佈局將有TextView內容或圖像。當內容沒有圖像的TextView發生同樣的事情。當圖像或文字不是佔用整個屏幕時不會發生這種情況。

肖像模式:

enter image description here

風景模式:

enter image description here

伴隨碼:

<LinearLayout 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:orientation="vertical" 
    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="net.vannevel.redditapp.activities.PostActivity"> 

    <TextView 
     android:id="@+id/postDetailTitle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:textColor="#000" /> 

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

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

      <ImageView 
       android:id="@+id/postDetailImage" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

      <TextView 
       android:id="@+id/postDetailBody" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 
     </LinearLayout> 
    </ScrollView> 

    <Button 
     android:id="@+id/postDetailViewOnlineButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:onClick="onViewOnlineButtonClicked" 
     android:text="View original source" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="COMMENTS" /> 

    <ListView 
     android:id="@+id/postDetailCommentList" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

回答

2

所以你的問題是你在滾動視圖內的項目比在橫向上的屏幕高度更高。即使你在ScrollView內滾動,一旦你完成了任何事情,你都無法做到。放置在ScrollView之外的所有元素都將脫離屏幕並放置在任何可滾動的容器之外。

我可以看到3級可能的解決方案:

1 - 集固定大小的滾動視圖,以便它不佔據整個屏幕,讓你讓對方意見不實用,但是:電話在風景意味着短高度,你必須適應圖片和列表與評論...

2 - 對景觀不同的佈局 - 在畫面左側,帶有關於意見的權利

3 - 擺脫ScrollView並設置一切ListView以上爲ListView頭(addHeaderView) 例如:

第1步 - 提取您對ListView頂部的一切,並把它變成一個不同的佈局文件 - 我們稱之爲header.xml

第2步 - 膨脹的佈局:

View headerView = inflater.inflate(R.layout.header, listView, false); 

第3步 - 初始化上,就像你現在做頭的項目

第4步 - 設置視圖列表ListView頭:

listView.addHeaderView(headerView, null, false); 

副作用這種方法的頭部,現在成爲ListView的一部分,它將在您滾動列表時滾動。此外,它會將您在適配器中的位置偏移1.

+0

我想一個單獨的佈局可能實際上是最有意義的。但是,即使在縱向模式下:例如,當文字對於屏幕來說太大時,它將被置於滾動視圖中,從而從屏幕移除其他項目(註釋)。由於它已經是肖像模式,我無法用其他佈局修復此問題。那麼建議的方法是什麼? –

+0

我會選擇#3或在不同的屏幕上顯示註釋。我會盡快更新答案,並提供更多有關選擇的詳細信息#3 –

+0

好吧,歡呼聲。這給了我足夠的工作。我很欣賞你提供的解釋。 –

1

變化:

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

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="300dp" 
      android:orientation="vertical"> 

或實施兩個layoutsportlandlandscape的方向。

+0

這並沒有什麼區別(500dp或其他)。我不知道如何創建不同的佈局文件會有所作爲,因爲它將與現在的佈局相同。 –

+0

你試過我的解決方案嗎? –

+0

我做過了,但是你把它放在錯誤的控件上:它是'ScrollView',它需要'layout_height'設置爲'300dp'。雖然這感覺有點不好意思,但我會牢記在心。 –