使用framelayout android中的按钮和listview创建重叠的linerlayout

时间:2015-12-28 11:54:48

标签: android android-framelayout

我有一个框架布局,第一个孩子作为列表视图

和第二个孩子作为线性布局,按钮很少

这样的事情,这只是一个示例图像而不是实际图像

enter image description here

这是我正在尝试的代码

ListView list;
LazyImageLoadAdapter mAdapter;

private final int AUTOLOAD_THRESHOLD = 4;
private final int MAXIMUM_ITEMS = 1052;

private View mFooterView;
private Handler mHandler;
private boolean mIsLoading = false;
private boolean mMoreDataAvailable = true;
private boolean mWasLoading = false;


private Runnable mAddItemsRunnable = new Runnable() {
    @Override
    public void run() {
        mAdapter.addMoreItems(10);
        mIsLoading = false;
    }
};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    list = (ListView) findViewById(R.id.list);

    // Create custom adapter for listview
    mAdapter = new LazyImageLoadAdapter(this, mStrings);

    // Set adapter to listview

    // Button b = (Button) findViewById(R.id.button1);
    // b.setOnClickListener(listener);

    mHandler = new Handler();
    // mAdapter = new SimpleAdapter(MainActivity.this,
    // android.R.layout.simple_list_item_1);
    mFooterView = LayoutInflater.from(this).inflate(R.layout.loading_view,
            null);
    list.addFooterView(mFooterView, null, false);
    // LIST(MADAPTER);
    list.setAdapter(mAdapter);

    list.setOnScrollListener(this);

}

@Override
public void onDestroy() {
    // Remove adapter refference from list
    list.setAdapter(null);
    super.onDestroy();
}

public OnClickListener listener = new OnClickListener() {
    @Override
    public void onClick(View arg0) {

        // Refresh cache directory downloaded images
        mAdapter.imageLoader.clearCache();
        mAdapter.notifyDataSetChanged();

    }
};

public void onItemClick(int mPosition) {
    String tempValues = mStrings[mPosition];

    Toast.makeText(MainActivity.this, "Image URL : " + tempValues,
            Toast.LENGTH_LONG).show();

}

// Image urls used in LazyImageLoadAdapter.java file

private String[] mStrings = {
        "http://androidexample.com/media/webservice/LazyListView_images/image0.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image1.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image2.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image3.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image4.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image5.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image6.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image7.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image8.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image9.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image10.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image0.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image1.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image2.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image3.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image4.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image5.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image6.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image7.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image8.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image9.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image10.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image0.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image1.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image2.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image3.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image4.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image5.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image6.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image7.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image8.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image9.png",
        "http://androidexample.com/media/webservice/LazyListView_images/image10.png"

};

@Override
public void onScroll(AbsListView view, int firstVisibleItem,
        int visibleItemCount, int totalItemCount) {
    if (!mIsLoading && mMoreDataAvailable) {
        if (totalItemCount >= MAXIMUM_ITEMS) {
            mMoreDataAvailable = false;
            list.removeFooterView(mFooterView);
        } else if (totalItemCount - AUTOLOAD_THRESHOLD <= firstVisibleItem
                + visibleItemCount) {
            mIsLoading = true;
            mHandler.postDelayed(mAddItemsRunnable, 1000);

        }
    }
}

@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
    // Ignore
}

@Override
public void onStart() {
    super.onStart();
    if (mWasLoading) {
        mWasLoading = false;
        mIsLoading = true;
        mHandler.postDelayed(mAddItemsRunnable, 1000);
    }
}

@Override
public void onStop() {
    super.onStop();
    mHandler.removeCallbacks(mAddItemsRunnable);
    mWasLoading = mIsLoading;
    mIsLoading = false;
}

显示按钮,并显示列表视图,但是当我点击按钮时,单击列表项并触发该事件

按钮单击侦听器就像这些

    <Framelayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" >
            <ListView
                android:id="@android:id/list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:drawSelectorOnTop="false" />
           <LinearLayout
            android:id="@+id/header"
            android:clickable="true"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="#000000"
              android:orientation="horizontal" >

            <ImageButton
                android:id="@+id/viewlist"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:clickable="true"
                android:background="#00000000"
                android:src="@drawable/ic_sort_by_alpha_white_48dp" />

            <ImageButton
                android:id="@+id/check"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                 android:clickable="true"
                android:background="#00000000"
                android:src="@drawable/ic_check_white_48dp" />



            <ImageButton
                android:id="@+id/shuffle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                 android:clickable="true"
                android:background="#00000000"
                android:src="@drawable/ic_shuffle_white_48dp" />

            <ImageButton
                android:id="@+id/share"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#00000000"
                 android:clickable="true"
                android:src="@drawable/ic_action_share" />

            <ImageButton
                android:id="@+id/search"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#00000000"
                 android:clickable="true"
                android:src="@drawable/ic_action_search" />


             <ImageButton
                android:id="@+id/settings"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="#00000000"
                 android:clickable="true"
                android:src="@drawable/ic_settings_applications_white_48dp" />

        </LinearLayout>
    </Framelayout>

和listvew有

shuffle.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "shuffle clicked ",
                        Toast.LENGTH_SHORT).show();
            }
        });

如何使包含按钮的布局与列表视图重叠并仍然可点击

1 个答案:

答案 0 :(得分:0)

可以通过以下方式更改您的设计来实现:包含按钮的布局将作为最终子项(相对布局)包含在框架布局中。这将允许您重叠Listview设计和静态按钮是可点击的。

 <Framelayout>
   <ListView
                android:id="@android:id/list"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:drawSelectorOnTop="false" />

<RelativeLayout
>
<!-- your button layout design !-->
</RelativeLayout>

<FrameLayout>