2016-08-06 28 views
0

我正在開發一個android項目,我添加了一個滾動活動。屏幕下端有一部分採用了背景顏色,使得一切看起來不整潔。 This is how it looks。我該如何解決?我想中間部分延伸到屏幕的底部,我嘗試了一切變化的高度,匹配到父母。沒有任何工作。您的幫助非常感謝!謝謝。代碼如下。我的滾動活動的佈局問題

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context=".ScrollingActivity" 
tools:showIn="@layout/activity_scrolling" 
android:background="@drawable/backgnd" 
android:layout_marginRight="24dp" 
android:layout_marginLeft="24dp"> 

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button1" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button2" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button3" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button4" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button5" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button6" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button7" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button8" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button9" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button10" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button11" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button12" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button13" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button14" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button15" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button16" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button17" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button18" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button19" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button20" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button21" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" 
      android:layout_gravity="center_horizontal" /> 

     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button22" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 


    </LinearLayout> 


</LinearLayout> 

+1

首先分享此佈局的xml。 – Vucko

+0

也發佈你的佈局,並清楚地說出你想要的佈局。 –

+0

@vucko我已經添加了XML。 –

回答

1

您可以使用列表視圖,讓您需要的佈局。由於listview本身是可滾動的,因此不需要添加單獨的滾動視圖。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/backgnd" 
android:layout_marginRight="24dp" 
android:layout_marginLeft="24dp"> 
     <ListView 
     android:id="@+id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 
</LinearLayout> 

然後定義另一佈局在列表視圖中的每個項目,例如作爲item.xml

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:baselineAligned="false"> 
     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_margin="@dimen/text_margin" 
      android:layout_weight="1" 
      android:text="This is a generic message" 
      android:layout_gravity="center_horizontal" /> 
     <Button 
      android:layout_width="48dp" 
      android:id="@+id/button22" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:background="@drawable/play" /> 
</LinearLayout> 

使用的適配器,以顯示在列表視圖的內容。在適配器的getView()函數中,您可以使用item.xml佈局來膨脹視圖。例如,

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    View rowView = mInflater.inflate(R.layout.item, parent, false); 
    return rowView; 
} 

這是給你的想法。請將其更改爲您的項目。