【问题标题】:create overlapping linerlayout with buttons and listview in framelayout android在framelayout android中使用按钮和listview创建重叠的linerlayout
【发布时间】:2015-12-28 20:14:43
【问题描述】:

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

第二个孩子是线性布局,按钮很少

类似这样的东西,这只是一个示例图像而不是实际图像

这是我正在尝试的代码

    <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>

显示按钮,下面的列表视图也会显示,但是当我单击按钮时,会单击列表项并触发该事件

按钮点击监听器是这样的

shuffle.setOnClickListener(new OnClickListener() {

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

listvew 有

 getListView().setOnItemClickListener(myOnItemClickListener);
    OnItemClickListener myOnItemClickListener = new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                long id) {

        }
    };

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

【问题讨论】:

  • 在 framelayout 中使用 Relativelayout ,然后在相对布局中使用 listview 和按钮内容。
  • 也试过了,还是listview项被点击了
  • 尝试为标题布局设置监听器。它可能会阻止 listitem click listener 。它只是一种解决方法。
  • 为什么需要框架布局?为什么不是相对布局?

标签: android android-framelayout


【解决方案1】:

这可以通过更改您的设计来实现,即包含按钮的布局将作为最终子项(相对布局)包含在框架布局中。这将允许您重叠 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-06
    • 2012-09-06
    • 2014-01-15
    • 1970-01-01
    • 2013-08-07
    相关资源
    最近更新 更多