简体   繁体   English

如何将滚动列表视图放入滚动视图?

[英]How to put a scroll listview in a scrollview?

I would like to get the list of my installed application in a listview for each application there is two toggleButton the first to add and the second is to protect (as shown by the image below ) 我想在每个应用程序的列表视图中获取已安装应用程序的列表,这里有两个toggleButton,第一个要添加,第二个是保护(如下图所示)。 名单 . I'd like in a first time to add a button after the list a tried to use a scroll view with no result. 我想第一次在列表后添加一个按钮,尝试使用没有结果的滚动视图。 The problem with a big list I can't find my button. 问题很大,我找不到我的按钮。

My two Layouts are given below : 我的两个布局如下:

<RelativeLayout 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" >
      <LinearLayout
        android:id="@+id/linear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:orientation="horizontal" 
       >

        <TextView
            android:id="@+id/maTextView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="180dip"
            android:gravity="center_vertical|center_horizontal"
            android:text="Ajouter                        Bloquer" />

    </LinearLayout>

    <ListView
        android:id="@+id/lv_countries"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linear"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:clickable="true"
        tools:context=".MainActivity" />
      <LinearLayout
        android:id="@+id/linear1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/lv_countries"
        android:orientation="horizontal" 
       >

        <Button
            android:id="@+id/button25"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Valider" >
        </Button>

    </LinearLayout>
</RelativeLayout>

and : 和:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/tv_item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:paddingLeft="5dp" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true" 
        android:layout_marginRight = "160dip">

        <ToggleButton
            android:id="@+id/tgl_status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:focusable="false"
            android:layout_marginRight="80dip" />


        <ToggleButton
            android:id="@+id/tgl_status1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:focusable="false" />
    </LinearLayout>


</RelativeLayout>

In a second time I would like to add the icon with the name of the aplication. 我想第二次添加带有应用名称的图标。 So I tried to change my Adapter the used one is 所以我试图改变我的适配器使用的是

SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.lv_layout, from, to);

I tried to creat an Adapter to use the icon of applications with their name my adapter: 我试图创建一个适配器,以使用名称为适配器的应用程序图标:

ublic class AppListAdapter extends BaseAdapter {

       private LayoutInflater mInflater;

       private List<App> mApps;
       /** a map which maps the package name of an app to its icon drawable */
       private Map<String, Drawable> mIcons;
       private Drawable mStdImg;

       /**
        * Constructor.
        * 
        * @param context the application context which is needed for the layout inflater
        */
       public AppListAdapter(Context context, List<HashMap<String, Object>> aList, int r, String[] from, int[]  to) {
          // cache the LayoutInflater to avoid asking for a new one each time
          mInflater = LayoutInflater.from(context);

          // set the default icon until the actual icon is loaded for an app
          mStdImg = context.getResources().getDrawable(R.drawable.icon);
       }

       @Override
       public int getCount() {
          return mApps.size();
       }

       @Override
       public Object getItem(int position) {
          return mApps.get(position);
       }

       @Override
       public long getItemId(int position) {
          return position;
       }

       @Override
       public View getView(int position, View convertView, ViewGroup parent) {

          AppViewHolder holder;
          if(convertView == null) {
             convertView = mInflater.inflate(R.layout.row, null);

             // creates a ViewHolder and stores a reference to the children view we want to bind data to
             holder = new AppViewHolder();
             holder.mTitle = (TextView) convertView.findViewById(R.id.apptitle);
             holder.mIcon = (ImageView) convertView.findViewById(R.id.appicon);
             convertView.setTag(holder);
          } else { 
             // reuse/overwrite the view passed assuming(!) that it is castable!
             holder = (AppViewHolder) convertView.getTag();
          }

          App app = mApps.get(position);

          holder.setTitle(app.getTitle());
          if (mIcons == null || mIcons.get(app.getPackageName()) == null) {
             holder.setIcon(mStdImg);
          } else {
             holder.setIcon(mIcons.get(app.getPackageName()));
          }

          return convertView; 
       }

       /**
        * Sets the list of apps to be displayed.
        * 
        * @param list the list of apps to be displayed
        */
       public void setListItems(List<App> list) { 
          mApps = list; 
       }

       /**
        * Sets the map containing the icons for each displayed app.
        * 
        * @param icons the map which maps the app's package name to its icon
        */
       public void setIcons(Map<String, Drawable> icons) {
          this.mIcons = icons;
       }

       /**
        * Returns the map containing the icons for each displayed app.
        * 
        * @return a map which contains a mapping of package names to icon drawable for all displayed apps
        */
       public Map<String, Drawable> getIcons() {
          return mIcons;
       }

       /**
        * A view holder which is used to re/use views inside a list.
        */
       public class AppViewHolder {

          private TextView mTitle;
          private ImageView mIcon;

          /**
           * Sets the text to be shown as the app's title
           * 
           * @param title the text to be shown inside the list row
           */
          public void setTitle(String title) {
             mTitle.setText(title);
          }

          /**
           * Sets the icon to be shown next to the app's title
           * 
           * @param img the icon drawable to be displayed
           */
          public void setIcon(Drawable img) {
             if (img != null) {
                mIcon.setImageDrawable(img);
             }
          }
       }
    }

and i call it using : 我用它来称呼它:

mAdapter = new AppListAdapter(getApplicationContext(), aList, R.layout.lv_layout, from, to);
        mAdapter.setListItems(mApps);

Just add the footer to the list view 只需将页脚添加到列表视图

View footer = getLayoutInflater().inflate(R.layout.footer, null);

Footer View can be the Button 页脚视图可以是按钮

listView.addFooterView(footer);

Make your parent layout as ScrollView 使您的父布局为ScrollView

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    >

    <RelativeLayout
        android:layout_width="318dp"
        android:layout_height="495dp"
         >

<LinearLayout
        android:id="@+id/linear"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:orientation="horizontal" 
       >

        <TextView
            android:id="@+id/maTextView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="180dip"
            android:gravity="center_vertical|center_horizontal"
            android:text="Ajouter                        Bloquer" />

    </LinearLayout>

    <ListView
        android:id="@+id/lv_countries"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linear"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:clickable="true"
        tools:context=".MainActivity" />
      <LinearLayout
        android:id="@+id/linear1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/lv_countries"
        android:orientation="horizontal" 
       >

        <Button
            android:id="@+id/button25"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Valider" >
        </Button>

    </LinearLayout>
</RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM