我一直在寻找这个问题的解决方案,我能找到的唯一答案似乎是" 不要将ListView放入ScrollView ".我还没有看到任何真正的解释为什么.我似乎找到的唯一原因是Google认为你不应该这样做.好吧,我做了,所以我做到了.
所以问题是,如何将ListView放入ScrollView而不将其折叠到最小高度?
我试图确定一个包含每行不同布局的单个ListView的最佳方法.我知道如何创建自定义行+自定义数组适配器以支持整个列表视图的自定义行,但是如何在ListView中实现许多不同的行样式?
我在滚动ListView里面遇到麻烦ScrollView.我有一个Activity在顶部有一些EditTexts,然后是一个带有两个选项卡的选项卡主机,每个选项卡都有一个ListView.当EditText视图聚焦时,软键盘出现,因为我有一个ScrollView,内容是可滚动的.但问题出现在ListViews中有更多项目(选项卡中的项目),即使有更多项目,我也无法滚动ListView.
以下是布局XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="?backgroundImage"
    android:orientation="vertical">
  <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:layout_alignParentBottom="true"
        android:layout_margin="10dip"
        android:id="@+id/buttons">
    <Button
            android:text="Save"
            android:layout_margin="2dip"
            android:textSize="20dip"
            android:id="@+id/btnSaveorUpdate"
            android:layout_height="wrap_content"
            android:layout_width="145dip"></Button>
    <Button
            android:text="Cancel"
            android:layout_margin="2dip"
            android:textSize="20dip"
            android:id="@+id/btnCancelorDelete"
            android:layout_height="wrap_content"
            android:layout_width="145dip"></Button>
  </LinearLayout>
  <ScrollView
        android:layout_above="@id/buttons"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        android:layout_margin="10dip">
    <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_margin="10dip">
      <TextView
                android:text="Bill details"
                android:textColor="?textColorDark"
                android:layout_alignParentTop="true"
                android:id="@+id/txtEnterDetails"
                android:textSize="25dip"
                android:textStyle="bold"
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:layout_marginBottom="2dip"></TextView>
      <LinearLayout
                android:focusable="true"
                android:focusableInTouchMode="true"
                android:layout_width="0dip"
                android:layout_height="0dip" />
      <EditText
                android:layout_width="fill_parent"
                android:hint="Enter data"
                android:inputType="numberDecimal"
                android:id="@+id/txtSample"
                android:textSize="@dimen/editText"
                android:layout_height="@dimen/editTextHeight"
                android:text=""></EditText>
      <EditText
                android:layout_width="fill_parent"
                android:id="@+id/txtDescription"
                android:hint="Enter description"
                android:textSize="@dimen/editText" …Run Code Online (Sandbox Code Playgroud) 我想为我的用户显示个人资料屏幕.
它必须有三个视图(2 Buttons和a ImageView)和a ListView以显示该用户所做的内容.
但是,我不想ListView滚动.相反,我希望它与所需的一样大,并将我的所有视图放在一个中ScrollView,所以三个第一个视图滚动出来ListView.当然,这不符合预期.
我的三件物品都在里面LinearLayout.我想把它们作为第一项ListView,但这导致它们可以作为第一项选择,并且不得不做一些不需要的编码.
有没有办法以简单的方式做到这一点,还是我必须坚持将布局作为ListView中的第一项?
我正在使用带有viewpager的CollapsingBarLayout,并且viewpager的片段具有listview,gridview.
这是我的代码:
    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.bigsteptech.seandroidnativeapp.classes.modules.common.ViewGroupEvent">
    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true">
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleTextAppearance="@style/TransparentText">
            <FrameLayout
                android:id="@+id/carouselLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_collapseMode="parallax">
                <ImageView
                    android:id="@+id/coverImage"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"/>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:gravity="bottom"
                    android:orientation="vertical"
                    android:layout_gravity="bottom"
                    android:padding="@dimen/profile_image_margin"
                    android:background="@drawable/gradient_bg"
                    android:layout_height="wrap_content">
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/profile_image_margin"
                        android:textSize="@dimen/text_size_xlarge"
                        android:textStyle="bold"
                        android:textColor="@color/white"
                        android:id="@+id/content_title"/>
                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_marginLeft="@dimen/profile_image_margin"
                        android:layout_height="wrap_content">
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textStyle="bold"
                            android:textColor="@color/white"
                            android:textSize="@dimen/text_size_medium"
                            android:id="@+id/category_title"/>
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:textStyle="bold"
                            android:layout_toRightOf="@+id/category_title"
                            android:layout_marginLeft="@dimen/profile_image_margin"
                            android:textColor="@color/white"
                            android:textSize="@dimen/text_size_medium"
                            android:id="@+id/memberCount"/>
                    </RelativeLayout>
                </LinearLayout>
            </FrameLayout>
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar" …Run Code Online (Sandbox Code Playgroud) 这篇文章与此ViewHolder无关.在这个职位,我下面就如何使用教程ViewHolder上ListView.我现在想要的是让a上的最后一个项目ListView具有与其余项目不同的布局.这是我的代码:
int lastpos = mList.size()-1;
          System.out.println("position: "+position+" mlist: "+lastpos);
          if(position==lastpos){
           view = vi.inflate(R.layout.list_item_record, null);
           holder.textView = (TextView)view.findViewById(R.id.record_view);
          }else{
           view = vi.inflate(R.layout.list_item_bn, null);
           holder.textView = (TextView)view.findViewById(R.id.tv_name);
          }
          view.setTag(holder);
Run Code Online (Sandbox Code Playgroud)
我只是得到ListView大小减去1并有一个条件,检查当前位置是否等于最后一项.但是,此代码将最后一个项目的布局设置为与其余项目相同.getView方法完整代码:
private class CustomListAdapter extends ArrayAdapter { 
    private ArrayList mList;
    private Context mContext;
    public CustomListAdapter(Context context, int textViewResourceId,
            ArrayList list) {
        super(context, textViewResourceId, list);
        this.mList = list;
        this.mContext = context;
    }   
    public View getView(final int position, View convertView, ViewGroup …Run Code Online (Sandbox Code Playgroud)