androidfadingedge
A. android 代码中设置控件的垂直居中和两个控件之间的距离。
首先是垂直居中,下面有朋友已经回答了,而控件和控件之间的距离设置是设置margin
B. android ListView中有某部分要点击效果,此点击效果是用selector实现,但在ListView中点击其他部分也会有效
tvFileNameAndSize.setText(attachFile.getFileName() + "(" + attachFile.getSize() + "K)");/*将文件名与文件大小添加到显示里*/
v.setTag(attachFile);/*将文件保存到控件里*/
ImageView ivDelete = (ImageView) v.findViewById(R.id.iv_iccfa_del);
ivDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View parent = (View) v.getParent();/*得到焦点*/
AttachFile file = (AttachFile) parent.getTag();/*将导入到这个位置的文件导出来*/
mFiles.remove(file);/*从自己的集合里移除它*/
mLlAttachFile.removeView(parent);/*从控件里将这个焦点所对应的内容删除*/
}
});
mLlAttachFile.addView(v);
ListView显示的格式是一个TextView加上一个ImageView,这个就是点击那个ImageView时删除这一条记录的部分代码,
C. android 怎么连接蓝牙设备
先展示代码结构
步骤阅读
2
连接蓝牙类
类名:MainActivity(有点偷懒,没有起表意的类名。)
步骤阅读
3
要声明的控件和变量等
步骤阅读
4
在onCreate声明控件
步骤阅读
5
ToogleButton设置开关状态
声明一个组件愿意接收
IntentFilter intent = new IntentFilter();
步骤阅读
6
BroadcastReceiver广播接收器
步骤阅读
步骤阅读
7
listview点击事件
OnItemClickListener
OnClickListener
步骤阅读
步骤阅读
8
蓝牙连接
步骤阅读
9
退出消耗页面是的onDestroy()
步骤阅读
10
布局结构图
<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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.bluetooth_connection.MainActivity" >
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="horizontal" >
<Button android:id="@+id/btnSearch" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="搜索" android:layout_weight="1" />
<Button android:id="@+id/btnExit" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="退出" android:layout_weight="1" />
<Button android:id="@+id/btnDis" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="开启蓝牙" android:layout_weight="1" /> </LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:orientation="vertical" >
<ToggleButton android:id="@+id/tbtnSwitch" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center_horizontal" android:textOff="关闭蓝牙" android:textOn="开启蓝牙" /> </LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="0.3" android:orientation="vertical" >
<ListView android:id="@+id/lvDevices" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#f1f1f1" android:cacheColorHint="#ff333333" android:fadingEdge="none" android:scrollbars="none" > </ListView> </LinearLayout> </LinearLayout>
</RelativeLayout>
步骤阅读
11
界面效果
步骤阅读
12
例子如下