Android 如何实现listview上的按钮(带有按钮的列表视图)(如给出的屏幕截图所示)
我正在尝试创建一个应用程序,在列表视图中有一个按钮,如下图所示。我应该能够单击并通过单击列表项导航到另一个页面,并且应该能够使用listview中的按钮(或开关)。我不知道它本身是否是一个列表视图 非常感谢您对一些示例代码的任何帮助Android 如何实现listview上的按钮(带有按钮的列表视图)(如给出的屏幕截图所示),android,android-layout,android-listview,Android,Android Layout,Android Listview,我正在尝试创建一个应用程序,在列表视图中有一个按钮,如下图所示。我应该能够单击并通过单击列表项导航到另一个页面,并且应该能够使用listview中的按钮(或开关)。我不知道它本身是否是一个列表视图 非常感谢您对一些示例代码的任何帮助 //试试这个 //try this hi this demo list item view you have modify as per requirement and also hide-show inner view like switch button sho
//试试这个
//try this
hi this demo list item view you have modify as per requirement and also hide-show inner view like switch button show on some cases..
**listitem.xml**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:adjustViewBounds="true"
android:src="@drawable/ic_launcher"/>
<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_marginLeft="3dp"
android:text="Power Saving"
android:ellipsize="end"/>
<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:checked="true"/>
</LinearLayout>
您好,此演示列表项视图您已根据要求进行修改,并在某些情况下隐藏显示内部视图,如开关按钮显示。。
**listitem.xml**
//试试这个
您好,此演示列表项视图您已根据要求进行修改,并在某些情况下隐藏显示内部视图,如开关按钮显示。。
**listitem.xml**
在列表中放大此视图,您将得到想要的。
在列表中放大此视图,您将得到想要的。
为此,您已经创建了自定义列表项视图xml。感谢您的回复。你能提供更多关于我如何实现这一点的细节吗。我必须做什么,怎么做?请给出一些伪代码。谢谢。您已经创建了自定义列表项视图xml。谢谢您的回复。你能提供更多关于我如何实现这一点的细节吗。我必须做什么,怎么做?请给出一些伪代码。谢谢
inflate this view in your list and you will get what you want.
<LinearLayout
android:layout_weight="3"
android:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:id="@+id/Imageview1"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="50dp"
android:adjustViewBounds="true"
android:src="@drawable/img"/>
<TextView
android:id="@+id/Textview1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:singleLine="true"
android:layout_marginLeft="3dp"
android:text="your text"
android:ellipsize="end"/>
<Switch
android:id="@+id/switch1"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:checked="true"/>
</LinearLayout>