Android自定义控件

android自定义按钮
1》定义按钮布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        androidrientation="horizontal"
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        >
    <ImageView
            android:id="@+id/iconMoney"
            android:layout_width="25dp"
            android:layout_height="fill_parent"
            >
    </ImageView>
    <TextView
            android:id="@+id/numMeoney"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:text="4444"
            android:textSize="20dp"
            android:layout_marginTop="0dp"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="8dp"
            >
    </TextView>
    <ImageView
            android:layout_marginLeft="5dp"
            android:id="@+id/iconAdd"
            android:layout_width="25dp"
            android:layout_height="fill_parent"
            >
    </ImageView>
</LinearLayout>

2》继承布局文件
package com.widget;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.dreamplanegames.R;
public class MoneyView extends LinearLayout {

    private ImageView iconMoney;
    private TextView textView;

    private ImageView Addmoney;

    public MoneyView(Context context,AttributeSet attributeSet) {
        super(context, attributeSet);
        LayoutInflater.from(context).inflate(R.layout.money, this,true);//指定布局

        this.iconMoney = (ImageView)findViewById(R.id.iconMoney);
        this.textView = (TextView)findViewById(R.id.numMeoney);
        this.Addmoney=(ImageView)findViewById(R.id.iconAdd);

        this.setClickable(true);//可以点击
        this.setFocusable(true);
    }

//设置控件内容
    public void setText(String text) {
        this.textView.setText(text);
    }

    public void setTextColor(int color) {
        this.textView.setTextColor(color);
    }

    public void setTextSize(float size) {
        this.textView.setTextSize(size);
    }

    public void setImg(Bitmap img1,Bitmap img2) {
        this.iconMoney.setImageBitmap(img1);
        this.Addmoney.setImageBitmap(img2);
        //this.yes.setImageBitmap(img2);
    }

}

3》控件的调用
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    androidrientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <ImageView android:id="@+id/mainMenuImage"
        android:src="@drawable/xk_bg2"
        android:scaleType="fitXY"
        android:layout_width="match_parent" 
        android:layout_height="match_parent">
    </ImageView>
//调用自定义控件
    <com.widget.MoneyView--------------------类名
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:id="@+id/btnMoney"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="20dp"
            >
    </com.widget.MoneyView>
</RelativeLayout>

4》到相应的activity调用
public class SFMainMenu extends Activity implements View.OnClickListener
{
    public MoneyView moneyview;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        //去除应用程序标题
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        //设置竖屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);   
        setContentView(R.layout.main);
//获取自定义按钮
        moneyview=(MoneyView)findViewById(R.id.btnMoney);
//调用自定义控件的函数设置控件内容
        moneyview.setImg(BitmapFactory.decodeResource(getResources(), R.drawable.money),BitmapFactory.decodeResource(getResources(), R.drawable.add));
        moneyview.setText(""+myPointBalance);

        //自定义按钮响应事件
        moneyview.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
         
            }
        });


}
    //返回键
    @Override
    public void onBackPressed() {
        super.onBackPressed();

    }

}

基于html+python+Apriori 算法、SVD(奇异值分解)的电影推荐算法+源码+项目文档+算法解析+数据集,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 电影推荐算法:Apriori 算法、SVD(奇异值分解)推荐算法 电影、用户可视化 电影、用户管理 数据统计 SVD 推荐 根据电影打分进行推荐 使用 svd 模型计算用户对未评分的电影打分,返回前 n 个打分最高的电影作为推荐结果 n = 30 for now 使用相似电影进行推荐 根据用户最喜欢的前 K 部电影,分别计算这 K 部电影的相似电影 n 部,返回 K*n 部电影进行推荐 K = 10 and n = 5 for now 根据相似用户进行推荐 获取相似用户 K 个,分别取这 K 个用户的最喜爱电影 n 部,返回 K*n 部电影进行推荐 K = 10 and n = 5 for now Redis 使用 Redis 做页面访问次数统计 缓存相似电影 在使用相似电影推荐的方式时,每次请求大概需要 6.6s(需要遍历计算与所有电影的相似度)。 将相似电影存储至 redis 中(仅存储 movie_id,拿到 movie_id 后还是从 mysql 中获取电影详细信息), 时间缩短至:93ms。 十部电影,每部存 top 5 similar movie 登录了 1-6 user并使用了推荐系统,redis 中新增了 50 部电影的 similar movie,也就是说,系统只为 6 为用户计算了共 60 部电影的相似度,其中就有10 部重复电影。 热点电影重复度还是比较高的
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值