当前位置:首页 » 安卓系统 » android基本控件

android基本控件

发布时间: 2022-06-22 06:44:12

㈠ 关于Android编程中的控件名称

我没有用过小米的系统,但从表现上来看很可能是
tabhost
也可以使用radiogroup来实现
还有pageview也可以。最主要看实现的人喜欢用
哪个控件

㈡ 最新的Android控件有哪些

1.MaterialStepperView
它是用Material Design实现Steppers的。

目前,Stepper只有垂直视图,但将来会有更多的风格。你可以尝试一下,如下图:
你可以自定义normal/active两个状态的颜色,完成图标,开启动画并设置动画时长。可通过Github上的设置项和样式查阅所有设置项。该库支持API 17+,详情请查阅wiki文档。

2. MultiSnapRecyclerView
这是分屏滚动的Android库。
MultiSnapRecyclerView为RecyclerView提供了分屏功能。

目前提供的功能有:
start, end和center三个位置的吸附,
snap count 指定要分屏的数量,
支持水平和垂直分屏,
滚动时的回调。
3. Garland View for Android
该库可实现如下的布局:

GarlandView 外部是一个水平滚动的视图,视图内的每一个子视图可垂直滚动。
你可以在README中找到其他重要信息。还有一个示例App。该库支持API 19及更高版本。
4. VegaLayoutManager
这是一个自定义的布局管理器——滚动时缩小并淡出头部。这是受到Dribble项目的启发。

5. ExpandableLayout
这个库的名字不言而喻,它是一个基于LinearLayout的可扩展的布局。
README里含有你启动时需要的所有信息,另外,还有一个示例App可以帮助你快速跳转到代码中。
6. SwipeBackLayout
SwipeBackLayout允许你使用手势返回上一个界面。
你可以设置滑动方向,如从左到右、从右到左、从顶部到底部、从底部到顶部。
你还可以设置是否只能从边缘滑动。
SwipeBackLayout只能包含一个子布局,例如:
LinearLayout,RelativeLayout,FrameLayout,TableLayout等。
ScrollView,HorizontalScrollView,NestedScrollView等。
RecyclerView,AbsListView(ListView)等子类。
ViewPager,WebView等。
该项目里面有一个详细说明的文档、示例APP和一个APK。

㈢ Android基础技术及基本控件

安卓基础技术主要是讲解一些安卓系统运行的原理,还有一些基本的组件,所有的安卓应用程序都是在这些组件构成的,基本控件主要就是一些类似按钮,进度条,滚动条这些图形界面组件,还有一些是用户自定义的组件。

㈣ 几个Android控件属性笔记

第一类:属性值为true或false
android:layout_centerHrizontal 水平居中 (Hrizontal表示水平)
android:layout_centerVertical 垂直居中 (Vertiacl表示垂直)
android:layout_centerInparent 相对于父元素完全居中
android:layout_alignParentBottom 贴紧父元素的下边缘 (align 表示使什么成为一行)
android:layout_alignParentLeft 贴紧父元素的左边缘
android:layout_alignParentRight 贴紧父元素的右边缘
android:layout_alignParentTop 贴紧父元素的上边缘
android:layout_alignWithParentIfMissing 如果对应的兄弟元素找不到的话就以父元素做参照物
第二类:属性值必须为id的引用名"@id/id-name"
android:layout_below 在某元素的下方
android:layout_above 在某元素的的上方
android:layout_toLeftOf 在某元素的左边
android:layout_toRightOf 在某元素的右边
android:layout_alignTop 本元素的上边缘和某元素的的上边缘对齐
android:layout_alignLeft 本元素的左边缘和某元素的的左边缘对齐
android:layout_alignBottom 本元素的下边缘和某元素的的下边缘对齐
android:layout_alignRight 本元素的右边缘和某元素的的右边缘对齐
第三类:属性值为具体的像素值,如30dip,40px
android:layout_marginBottom 离某元素底边缘的距离 margin英文是边缘的意思
android:layout_marginLeft 离某元素左边缘的距离
android:layout_marginRight 离某元素右边缘的距离
android:layout_marginTop 离某元素上边缘的距离

㈤ android界面开发常用的控件有哪些

控件开发大致分为两种: 1.组合式开发。将几个android现成的控件,如ImageView,Button等糅合在一起。 2.单独开发。一般继承View,然后重写其onDraw和onMeasure等方法。若是ViewGroup,则还需重写measureChildren等。 上面说的是2D控件。3D则需继承SurfaceView。

㈥ android自定义控件怎么用

一、控件自定义属性介绍
以下示例中代码均在values/attrs.xml 中定义,属性均可随意命名。
1. reference:参考某一资源ID。
示例:
<declare-styleable name = "名称">

<attr name = "background" format = "reference" />
<attr name = "src" format = "reference" />
</declare-styleable>

2. color:颜色值。
示例:
<declare-styleable name = "名称">

<attr name = "textColor" format = "color" />
</declare-styleable>

3. boolean:布尔值。
示例:
<declare-styleable name = "名称">

<attr name = "focusable" format = "boolean" />
</declare-styleable>

4. dimension:尺寸值。
示例:
<declare-styleable name = "名称">

<attr name = "layout_width" format = "dimension" />
</declare-styleable>

5. float:浮点值。
示例:
<declare-styleable name = "名称">

<attr name = "fromAlpha" format = "float" />
<attr name = "toAlpha" format = "float" />
</declare-styleable>

6. integer:整型值。
示例:
<declare-styleable name = "名称">

<attr name = "frameDuration" format="integer" />
<attr name = "framesCount" format="integer" />
</declare-styleable>

7. string:字符串。
示例:
<declare-styleable name = "名称">

<attr name = "text" format = "string" />
</declare-styleable>

8. fraction:百分数。
示例:

<declare-styleable name="名称">
<attr name = "pivotX" format = "fraction" />
<attr name = "pivotY" format = "fraction" />
</declare-styleable>

9. enum:枚举值。
示例:
<declare-styleable name="名称">

<attr name="orientation">
<enum name="horizontal" value="0" />
<enum name="vertical" value="1" />
</attr>
</declare-styleable>

10. flag:位或运算。
示例:
<declare-styleable name="名称">

<attr name="windowSoftInputMode">
<flag name = "stateUnspecified" value = "0" />
<flag name = "stateUnchanged" value = "1" />
<flag name = "stateHidden" value = "2" />
<flag name = "stateAlwaysHidden" value = "3" />
</attr>
</declare-styleable>

11.多类型。
示例:

<declare-styleable name = "名称">
<attr name = "background" format = "reference|color" />
</declare-styleable>

二、属性的使用以及自定义控件的实现
1、构思控件的组成元素,思考所需自定义的属性。
比如:我要做一个 <带阴影的按钮,按钮正下方有文字说明>(类似9宫格按钮)
新建values/attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="custom_view">
<attr name="custom_id" format="integer" />
<attr name="src" format="reference" />
<attr name="background" format="reference" />
<attr name="text" format="string" />
<attr name="textColor" format="color" />
<attr name="textSize" format="dimension" />
</declare-styleable>
</resources>

以上,所定义为custom_view,custom_id为按钮id,src为按钮,background为阴影背景,text为按钮说明,textColor为字体颜色,textSize为字体大小。

2、怎么自定义控件呢,怎么使用这些属性呢?话不多说请看代码,CustomView :

package com.nanlus.custom;
import com.nanlus.custom.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomView extends FrameLayout implements OnClickListener {
private CustomListener customListener = null;
private Drawable mSrc = null, mBackground = null;
private String mText = "";
private int mTextColor = 0;
private float mTextSize = 20;
private int mCustomId = 0;
private ImageView mBackgroundView = null;
private ImageButton mButtonView = null;
private TextView mTextView = null;
private LayoutParams mParams = null;
public CustomView(Context context) {
super(context);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.custom_view);
mSrc = a.getDrawable(R.styleable.custom_view_src);
mBackground = a.getDrawable(R.styleable.custom_view_background);
mText = a.getString(R.styleable.custom_view_text);
mTextColor = a.getColor(R.styleable.custom_view_textColor,
Color.WHITE);
mTextSize = a.getDimension(R.styleable.custom_view_textSize, 20);
mCustomId = a.getInt(R.styleable.custom_view_custom_id, 0);
mTextView = new TextView(context);
mTextView.setTextSize(mTextSize);
mTextView.setTextColor(mTextColor);
mTextView.setText(mText);
mTextView.setGravity(Gravity.CENTER);
mTextView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mButtonView = new ImageButton(context);
mButtonView.setImageDrawable(mSrc);
mButtonView.setBackgroundDrawable(null);
mButtonView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mButtonView.setOnClickListener(this);
mBackgroundView = new ImageView(context);
mBackgroundView.setImageDrawable(mBackground);
mBackgroundView.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
addView(mBackgroundView);
addView(mButtonView);
addView(mTextView);
this.setOnClickListener(this);
a.recycle();
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mParams = (LayoutParams) mButtonView.getLayoutParams();
if (mParams != null) {
mParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
mButtonView.setLayoutParams(mParams);
}
mParams = (LayoutParams) mBackgroundView.getLayoutParams();
if (mParams != null) {
mParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
mBackgroundView.setLayoutParams(mParams);
}
mParams = (LayoutParams) mTextView.getLayoutParams();
if (mParams != null) {
mParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
mTextView.setLayoutParams(mParams);
}
}
public void setCustomListener(CustomListener l) {
customListener = l;
}
@Override
public void onClick(View v) {
if (customListener != null) {
customListener.onCuscomClick(v, mCustomId);
}
}
public interface CustomListener {
void onCuscomClick(View v, int custom_id);
}
}
代码很简单,就不多说,下面来看看我们的CustomView是怎么用的,请看:

3、自定义控件的使用
话不多说,请看代码,main.xml:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:nanlus="http://schemas.android.com/apk/res/com.nanlus.custom"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="horizontal" >
<com.nanlus.custom.CustomView
android:id="@+id/custom1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
nanlus:background="@drawable/background"
nanlus:custom_id="1"
nanlus:src="@drawable/style_button"
nanlus:text="按钮1" >
</com.nanlus.custom.CustomView>
</LinearLayout>
</RelativeLayout>

在这里需要解释一下,
xmlns:nanlus="http://schemas.android.com/apk/res/com.nanlus.custom"
nanlus为在xml中的前缀,com.nanlus.custom为包名

4、在Activity中,直接上代码
package com.nanlus.custom;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.nanlus.BaseActivity;
import com.nanlus.custom.R;
import com.nanlus.custom.CustomView.CustomListener;
public class CustomActivity extends BaseActivity implements CustomListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
((CustomView) this.findViewById(R.id.custom1)).setCustomListener(this);
}
@Override
public void onCuscomClick(View v, int custom_id) {
switch (custom_id) {
case 1:
Toast.makeText(this, "hello !!!", Toast.LENGTH_LONG).show();
break;
default:
break;
}
}
}

㈦ 如何系统的学习android自定义各种酷炫控件

首先,为什么需要自定义View?

1. 现有的View满足不了你的需求,也没有办法从已有控件派生一个出来;界面元素需要自己绘制。
2. 现有View可以满足要求,把它做成自定义View只是为了抽象:为这个自定义View提供若干方法,方便调用着操纵View。通常做法是派生一个已有View,或者结合xml文件直接inflate。

目前常用的基本上是第二种方式,这种方式非常简单,与通常的View使用方法基本相同,但是作用却异常强大,拥有了这一层抽象,代码更加整洁也更容易维护,通过抽取自定义View的公共操作方法也减少了冗余代码,虽然简单,但不可忽视。

大多数人感觉神秘的应该是第一种,自绘控件,完全自定义;但其实这两种方式归根结底全部都是自绘;不信你去看看TextView的源码。只不过通常情况下系统帮我们绘制好了一些控件给开发者使用;OK,接下来就是一个问题。

在讲述之前我还是啰嗦地重申一下,复用已有View是最最常用也最有效的自定义View方式,必须熟练使用。

其次,如何自定义View?

想一下,一个View给用户最直观的感知是什么?静止的形态和动态的操作。静止的形态意思就是一个View呈现到用户眼里长成啥样子?动态操作指的是,用户与View之间可以有哪些交互?点击滑动View的不同地方会有什么反应?

1. 静态

如果一个自定义View的样式都没有办法绘制出来,那么后续的交互就是空谈了;我们一步步分解这个问题。

1.1 你的自定义View分为哪几个部分?是所有的部分都需要手动绘制还是只有一部分——找出需要完全自定义的部分,其他的部分用已有View实现。

1.2 你的自定义View的每个部分长成什么样,占用多大空间——结合理论知识View的measure过程,比如match_parent, wrap_content结合父View的laout_params参数最终测量大小是多少?

1.3 你的自定义View每个部分摆放在哪?相对位置如何?——View的layout过程。

1.4 你的自定义View那些完全需要手动绘制的部分是什么样,如何绘制?

你得学会操纵Canvas,学会2D绘图,什么?你跟我说3D,OpenGL?学会这些再说。

㈧ android列表常用控件有哪些

一、概述 Android中的有个原生的下拉列表控件Spinner,但是这个控件有时候不符合我们自己的要求, 比如有时候我们需要类似windows 或者web网页中常见的那种下拉列表控件,类似下图这样的: 这个时候只有自己动手写一个了。其实实现起来不算很难, 本文实现的方案是采用TextView +ImageView+PopupWindow的组合方案。 先来看看我们的自己写的控件效果图吧:(源码在文章下面最后给出哈!) 二、自定义下拉列表框控件的实现 1. 自定义控件用到的布局文件和资源: 结果框的布局页面:dropdownlist_view.xml: <?xml version="1.0" encoding="utf-8"?>

㈨ android这么多ui控件怎样才能记牢呢

布局(Layout)的概念是针对Activity的,Activity就是布满整 个Android设备的窗口或者悬浮于其他窗口上的交互界面。在一个应用程序中通常由多个Activity构成,每个需要显示的Activity都需要在AndroidManifest.xml文件之中声明。

通常情况下,开发人员可以使用两种方式来创建UI组件,一种方式是使用XML方式来配置UI组件的相关属性,然后装载这些UI组件,这也是最常用的方式。但是有些特殊情况下,需要动态生成UI组件,则需要使用第二种方式,完全使用java代码来创建UI组件。

XML布局文件是Android系统中定义的Layout的常用方式,所有布局文件必须包含在res/layout目录中,且必须符合Java的命名 规范。当在res/layout目录下新增了布局文件之后,R.java文件会自动收录该布局资源,Java代码可通过setContentView方法 在Activity中显示该Layout。

setContentView(R.layout.<资源名称>);

在布局文件中可以指定UI组件的android:id属性,该属性的属性值代表该组件的唯一标识。通过Activity.findViewById()访问,并且findViewById()必须在setContentView加载xml文件之后使用,否则会抛出异常。

findViewById(R.id.)

Android应用的绝大部分UI组件都放在android.widget包及其子包、android.view包及其子包中,Android应用的 所有UI组件都继承了View类。View类还有一个重要的子类:ViewGroup,ViewGroup类是所有布局管理器的父类。

ViewGroup容器控制其子组件的分布依赖于ViewGroup.LayoutParams、ViewGroup.MarginLayoutParams两个内部类。

ViewGroup.LayoutParams提供两个XML属性设定组件的大小。

android:layout_height:指定该子组件的基本高度;

android:layout_width:指定该子组件的基本宽度。

这两个属性有三个基本值,这两个属性有三个特定的值:

fill_parent:指定组件的高度、宽度与父容器组件的一样。

match_parent:与fill_parent一样,Android2.2开始推荐使用。

warp_content:内容包裹。

ViewGroup.MarginLayoutParams用于控制子组件周围的页边距。

android:layout_marginBottom(下边距);

android:layout_marginLeft(左边距);

android:layout_marginRight(右边距):

layout_marginTop(上边距)

对于View的尺寸,android提供了三种单位供选择使用:

px:像素。

dp:dpi,表示屏幕实际的像素。

sp:与scale无关的像素,与dp类似。

尺寸单位选择的技巧:如果设置长度、高度等属性时可以使用dp或sp,但是如果设置字体,需要使用px。如果使用dp或sp,系统会根据屏幕密度的变化进行转换。

为了适应各种界面风格,Android提供了五种布局规范,利用这五种布局,基本上可以在设备上随心所欲的摆放任何UI组件,这五种布局分别是:

FrameLayout(帧布局)。

LinearLayout(线性布局)

RelativeLayout(相对布局)。

TableLayout(表格布局)。

AbsoluteLayout(绝对布局)。

线性布局(LinearLayout)

LinearLayout是最常用的布局方式,在XML文件中使用标记。它会将容器里的UI组件一个一个挨着排列起来。但是LinearLayout不会换行,当UI组件超出屏幕之后,则不会被显示出来。LinearLayout有两个重要的XML属性:androidgravity(对齐方 式);android:orientation(排列方式)。

android:orientation(排列方式),设定了LinearLayout中包含的UI组件的排列方式,有两个选项vertical(竖向)、horizontal(横向,默认值)

android:gravity(对齐方式),设定LinearLayout中包含UI组件的对齐方式,其选项很多,常用上(top)、下(bottom)、左(left)、右(right)。

热点内容
php配置mail 发布:2024-05-19 11:52:37 浏览:906
欧洲国家的云服务器 发布:2024-05-19 11:43:30 浏览:44
左游手柄助手2脚本 发布:2024-05-19 11:40:28 浏览:1002
挖矿需要什么配置 发布:2024-05-19 11:38:02 浏览:895
eclipse导出ant脚本 发布:2024-05-19 11:20:28 浏览:99
如何改变vivo手机账户密码 发布:2024-05-19 10:56:07 浏览:377
sql的length函数 发布:2024-05-19 10:55:15 浏览:546
数据库管理系统设计报告 发布:2024-05-19 10:49:50 浏览:685
linux怎么将驱动编译进内核 发布:2024-05-19 10:23:47 浏览:768
c语言读程序题 发布:2024-05-19 10:13:52 浏览:675