如何在Android中实现这一点
我是Android新手。有人能告诉我这是什么类型的技术吗?我想在密码字段中添加此功能。我可以知道实现我的目标的正确方法是什么吗?你能帮我提供一些代码或链接到如何正确实现这一目标的指南吗?你有很多可能创建这种布局:如何在Android中实现这一点,android,Android,我是Android新手。有人能告诉我这是什么类型的技术吗?我想在密码字段中添加此功能。我可以知道实现我的目标的正确方法是什么吗?你能帮我提供一些代码或链接到如何正确实现这一目标的指南吗?你有很多可能创建这种布局: 父级RelativeLayout,顶部和底部各有4个点的LinearLayout显示您的视图以及as-toLeftOf、toRightOf等-使用onClickListener方法更改其状态并保存数字 多个LinearLayouts和weight属性填充整个空间,每个视图(四舍五入的
- 父级
,顶部和底部各有4个点的RelativeLayout
显示您的视图以及as-toLeftOf、toRightOf等-使用LinearLayout
方法更改其状态并保存数字onClickListener
- 多个
s和LinearLayout
属性填充整个空间,每个视图(四舍五入的数字)填充空间(请参见下面的示例以了解weight属性)-或多个weight
s-甚至一个RelativeLayout
李>TableLayout
- 或者使用
方法在下面的项ClickListener
和线性布局
网格视图
<!-- named activity_main.xml -->
<RelativeLayout
... >
<LinearLayout
android:id="@+id/contain"
... android:layout_width="250dip"
android:orientation="horizontal"
android:weightSum="4" >
<!-- weightSum to 4 = whatever the screen, display
my children views in 4 sections -->
<View
... android:layout_weight="1"
android:background="@drawable/green_dots" />
<!-- weight to 1 = this takes one section -->
<View
... android:layout_weight="1"
android:background="@drawable/green_dots" />
<!-- weight to 1 = this takes one section -->
<View
... android:layout_weight="1"
android:background="@drawable/green_dots" />
<View
... android:layout_weight="1"
android:background="@drawable/green_dots" />
</LinearLayout>
<RelativeLayout
android:layout_below="@id/contain" ... >
... Here display your buttons (or textviews) with
custom drawable background for each one
</RelativeLayout>
然后在此活动内的方法中:
// init your buttons var
Button one, two, three, four, five ...;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// set the layout above
setContentView(R.layout.activity_main);
// init your buttons
one = (Button) findViewById(R.id.button1);
two = (Button) findViewById(R.id.button2);
three = (Button) findViewById(R.id.button3);
... etc.
// set them to your implementation
one.setOnClickListener(this);
two.setOnClickListener(this);
three.setOnClickListener(this);
... etc.
}
// call this function when one button is pressed
public void onClick(View view) {
// retrieves the id of clicked button
switch(view.getId()) {
case R.id.button1:
methodToSaveNumber(int);
break;
case R.id.button2:
methodToSaveNumber(int);
break;
case R.id.button3:
methodToSaveNumber(int);
break;
... etc.
}
}
然后在方法到savenumber
方法中:
// finally, your method to save the number of the password
public void methodToSaveNumber(int i) {
... do something.
... change the state of the buttons, the dots, whatever you want
}
为了向您展示它的工作原理,可绘制的绿点可能如下所示:
public class MyActivity extends Activity implements OnClickListener { }
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<!-- radius -->
<corners
android:radius="20dp" />
<!-- border -->
<stroke
android:color="@android:color/green"
android:width="2dp" />
<!-- background (transparent) -->
<solid
android:color="#00000000" />
</shape>
你必须告诉你它是如何工作的,它是如何工作的,它是如何工作的,它是如何工作的(聚焦的,被压制的,被禁用的,…),最后,我希望你能得到你想要的
快乐编码 具有圆形背景和相对位置的按钮。顶部是一个圆形的空视图,其中填充了代码。是否有相关链接/教程@Marcociernoi认为rel中有10个按钮。具有4个圆形图像的相对布局下方的布局。。然后第一个密码被截取,然后在第一个rel布局中更改第一个btn的图像。。对图像的顶部插脚重复4次,创建方向为水平的线性布局,并在其中添加四个ImageView
s。对于键,创建一个GridView
,项目计数等于12,并在getView()
中返回ImageView
s,返回ImageView
s,位置为9和11的透明图像…@GopalRao先生,有任何演示/教程吗?谢谢回答。我想补充一下你的方法。很乐意帮忙。不确定这是否是最好的,但这可能是一个好的开始,我认为当你开始时,这是一个简单的开始。我认为你已经有了一个答案@IntelliJAmiya:)在第一个活动(a)上使用SharedReferences,保存活动状态并在重新打开应用程序时检索它们。这应该行得通,而且不难做到。