我正在开发一个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>
答案 0 :(得分:1)
您可以使用listview获取所需的布局。由于listview本身是可滚动的,因此无需添加单独的scrollview。
<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;
}
这是为了给你一个想法。请将其更改为您的项目。