石家庄制作网站公司有哪些,网站如何改首页模块,网业浏览设置在哪,陕西省住房和建设厅官方网站1、如何在一个按钮上放上一张图片#xff1f;把按钮和图片套在一个FrameLayout中 !-- 必须将button和ImageView分别嵌套在两个LinearLayout中才能 实现将图片放在按钮上 -- FrameLayout android:orientationhorizontal android:layout_width把按钮和图片套在一个FrameLayout中 !-- 必须将button和ImageView分别嵌套在两个LinearLayout中才能 实现将图片放在按钮上 -- FrameLayout android:orientationhorizontal android:layout_widthwrap_content android:layout_heightwrap_content LinearLayout android:layout_widthwrap_content android:layout_heightwrap_content Button stylestyle/menu_btn_style android:idid/fan_us android:textstring/mainmenu_facebook_fan_us / /LinearLayout LinearLayout android:layout_widthwrap_content android:layout_heightwrap_content ImageView android:layout_widthwrap_content android:layout_heightwrap_content android:layout_marginLeft16dp android:layout_marginTop13dp android:srcdrawable/facebookicon / /LinearLayout /FrameLayout 2、如何自定义组件自定义一个下划线形式的输入框 第一确定要画多少条下划线第二每条线的宽度第三下划线的间距 1自定义文本输入框package com.heima.guesswho.util; import com.heima.android.guesswho.R; import android.content.Context;import android.content.res.TypedArray;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.util.AttributeSet;import android.widget.EditText; public class DashlineEditText extends EditText { /* * 假设下划线总长100个单位要画7条下划线每条下划线间距为2个单位 * 具体算法如下 * 每条下划线的长度(1002)/7-2 * for(int i 0;i7,i){ * 第i条线 * x1 ((1002)/7)*i * y1 getHeight() * x2 ((1002)/7)*i(1002)/7-2 * y2 getHeight() * } * */ private Paint linePaint new Paint(); private int segmentCount 8;//总共画8条分割线可以作为默认值 private int distance 5;//每个分割线的间距为4个单位可以作为默认值 /* * 从布局文件中得到对应属性的值 */ public DashlineEditText(Context context, AttributeSet attrs) { super(context, attrs); setBackgroundDrawable(null);//消除文本框效果的作用 //linePaint.setColor(Color.RED);//设置画笔的颜色 TypedArray array context.obtainStyledAttributes(attrs, R.styleable.DashLineET); segmentCount array.getInt(R.styleable.DashLineET_segment_count, segmentCount);//从指定属性中拿到对应的值若没设置则用默认值 distance array.getInt(R.styleable.DashLineET_distance, distance); int color array.getInt(R.styleable.DashLineET_dashline_color, Color.RED); linePaint.setColor(color); } Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int width getWidth();//自定义控件的宽度 int height getHeight()-3;//必须减去数才能显示出下划线 //画出每一条下划线 for(int i 0; i segmentCount; i){ int oneSegmentWidth (widthdistance)/segmentCount - distance;//每条下划线的长度 int startX (segmentCountdistance)*i ;//每条下划线的起点位置 int stopX startXoneSegmentWidth ;//每条下划线的终点位置 canvas.drawLine(startX, height, stopX, height, linePaint); } }} 2布局文件?xml version1.0 encodingutf-8?LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/android android:orientationvertical android:layout_widthfill_parent android:layout_heightfill_parent TextView android:layout_widthfill_parent android:layout_heightwrap_content android:textstring/debug_name / com.heima.guesswho.util.DashlineEditText android:layout_width100dp android:layout_height12dp android:texttest //LinearLayout 定义自定义组件的属性 第一步在string.xml文件中配置declare-styleable !-- 定义DashLineEditText的属性 -- declare-styleable nameDashLineET attr namesegments_cnt formatinteger / attr namedistance formatdimension / attr namedashline_color formatcolor / attr namehint_msg formatreference / attr namehint_color formatcolor / /declare-styleable 第二步在自定义组件中复写构造方法用来获取布局文件中属性的值 /* * 从布局文件中得到对应属性的值 */ public DashlineEditText(Context context, AttributeSet attrs) { super(context, attrs); setBackgroundDrawable(null);//消除文本框效果的作用 //linePaint.setColor(Color.RED);//设置画笔的颜色 TypedArray array context.obtainStyledAttributes(attrs, R.styleable.DashLineET); segmentCount array.getInt(R.styleable.DashLineET_segment_count, segmentCount);//从指定属性中拿到对应的值若没设置则用默认值 distance array.getInt(R.styleable.DashLineET_distance, distance); int color array.getInt(R.styleable.DashLineET_dashline_color, Color.RED); linePaint.setColor(color); } 第三步在使用自定义组件的布局文件中加入命名空间 如xmlns:heimahttp://schemas.android.com/apk/res/com.heima.android.guesswho heima 为我们使用属性时使用的前缀相当于使用Android属性时要使用android前缀一样其中com.heima.android.guesswho为清单文件标识应用的包名 布局文件如下 ?xml version1.0 encodingutf-8?LinearLayout xmlns:androidhttp://schemas.android.com/apk/res/android xmlns:heimahttp://schemas.android.com/apk/res/com.heima.android.guesswho android:orientationvertical android:layout_widthfill_parent android:layout_heightfill_parent TextView android:layout_widthfill_parent android:layout_heightwrap_content android:textstring/debug_name / com.heima.guesswho.util.DashlineEditText android:layout_width100dp android:layout_height12dp heima:segment_count10 heima:distance3 android:texttest //LinearLayout com.heima.guesswho.util.DashlineEditText android:layout_width210dip heima:segment_count9 heima:distance4dip heima:dashline_colorcolor/font_white android:layout_heightwrap_content android:textColor#FF0000 android:hintstring/input_name_prompt android:text /转载于:https://www.cnblogs.com/csj007523/archive/2011/07/04/2097510.html