ScrollView 部分布局
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/part_line"
android:layout_above="@id/pay_go"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="5dp"
android:orientation="vertical"
android:id="@+id/pay_main_info">
<include layout="@layout/add_address"
android:id="@+id/address_desc"/>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
/>
<include layout="@layout/pay_other_info"
android:id="@+id/pay_other_info"/>
<View
android:layout_width="match_parent"
android:layout_height="5px"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="桃李园"
android:textSize="25dp"
android:layout_marginLeft="20dp"
android:textColor="@color/black"
android:id="@+id/pay_order_form_canteen_name"/>
<View
android:layout_width="match_parent"
android:layout_height="5px"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
/>
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:id="@+id/pay_order_form_foodlist">
</ListView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="添加备注"
android:drawableRight="@mipmap/more"
android:textSize="20dp"
android:layout_marginLeft="20dp"
android:textColor="@color/black"
android:layout_marginRight="20dp"
android:clickable="true"
android:id="@+id/pay_order_form_add_remakes"/>
</LinearLayout>
</ScrollView>
布局效果图:

实际效果图:

期望效果:
实现类似于饿了么的那种界面,把listview的界面填充出去,如图下:

TextView的设置background的bug:
TextView代码:
<TextView
android:id="@+id/add_address_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/text_bg"
android:gravity="center"
android:paddingBottom="20dip"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:paddingTop="20dip"
android:text="+添加收货地址"
android:textColor="@color/theme_blue_two"
android:textSize="30sp"
android:layout_centerHorizontal="true"
/>
效果:

background的效果并没有运用上去,附其他可用的TextView的效果,如图下:

你这属于滑动空间嵌套滑动空间问题 需要重写listview 要不然就会出现显示不全的问题 还有滑动冲突问题
自定义一个listview 继承 listview 重写onmeasure 方法 重新测量高度
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int measureSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, measureSpec);
}
很简单 重写这一个方法就可以 然后再xml 文件中引用就好了 你试一下
ScrollView滚动视图是指当拥有很多内容、屏幕显示不完时、需要通过滚动跳来显示的视图、Scrollview的一般用法如下、以下代码在Scrollview里面放了一个RelativeLayout、并且是设置为android:layout_height="match_parent"填充全屏的,但是测试以后不起作用。布局如下:
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/common_background" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:background="@drawable/bottom_bg" />
</RelativeLayout>
查看android API 获知,
其中白色部分是scrollView,灰色部分是TextView,很明显,scrollview(白色)已经扩展到最大高度了,但是其内部的TextView(灰色)却没有扩展.可明明TextView的layout_height="fill_parent",为什么没占满呢?是因为TextView的上层LinearLayout为wrap_content的原因吗?
但是换成fill_parent还是一样的(实际上Scrollview的第一层View的layout_weight在sdk中是建议为wrap_content的)。
后来在stackoverflow上找到了原因: http://stackoverflow.com/questions/2599837/linearlayout-not-expanding-inside-a-scrollview
要让ScrollView内部元素的 fill_parent 起作用必须设置android:fillViewport="true"
1
2
3
4
5
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
完整的listview
public class MyListView extends ListView {
public MyListView(Context context) {
super(context);
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int measureSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, measureSpec);
}
}