Android 我想动画化我的输入数字布局并将其放在底部布局的顶部
Android i want to animate-down my Enter number Layout and place it on top of bottom Layout
我想在键盘折叠图像点击时隐藏我的键盘,并为我的拨号盘输入数字相对布局设置为底部呼叫布局的上部
但我想为我的输入数字编辑文本布局设置动画以放置在底部布局上,请任何人帮助我。
这是我的代码
public class MainActivity extends ActionBarActivity {
private GridView gridView;
private TextView grid_num_tv;
private EditText phone_num_edt;
private RelativeLayout gridView_collapse_rl, dialPad_overflow_rl, dialPad_num_edt_rl;
private ImageView dialPad_collapse_iv;
static final String[] GRID_NUM = new String[] {
"1", "2", "3",
"4", "5", "6",
"7" ,"8", "9" ,
"*", "0", "#"};
static final String[] GRID_LETTERS = new String[] {
" ", "abc", "def",
"ghi", "jkl", "mno",
"pqrs" ,"tuv", "wxyz" ,
" ", "+", " "};
Context context;
ArrayList<GridListDataModel> myGridList = new ArrayList<GridListDataModel>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = (GridView) findViewById(R.id.gridView1);
phone_num_edt = (EditText) findViewById(R.id.dial_pad_num_editText);
gridView_collapse_rl = (RelativeLayout) findViewById(R.id.dial_close_rl);
dialPad_overflow_rl = (RelativeLayout) findViewById(R.id.dial_overflow_rl);
dialPad_collapse_iv = (ImageView) findViewById(R.id.dialpad_collapse_imageView);
dialPad_num_edt_rl = (RelativeLayout) findViewById(R.id.dial_num_edt_rl);
gridView.setVisibility(View.VISIBLE);
gridView.setAdapter(new CustomGridAdapter(this, GRID_NUM));
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
grid_num_tv = (TextView) view.findViewById(R.id.grid_num_textView);
Toast.makeText(getApplicationContext(), grid_num_tv.getText(), Toast.LENGTH_SHORT).show();
}
});
gridView_collapse_rl.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(gridView.isShown()){
dialPad_collapse_iv.setImageResource(R.drawable.ic_action_collapse);
gridView.setVisibility(View.INVISIBLE);
}else{
dialPad_collapse_iv.setImageResource(R.drawable.ic_action_expand);
gridView.setVisibility(View.VISIBLE);
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml 是我的主要布局 xml 文件
<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.gridviewdemo.MainActivity" >
<RelativeLayout
android:id="@+id/dialpad_bottom_rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<RelativeLayout
android:layout_width="60dp"
android:layout_height="45dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_toLeftOf="@+id/dial_overflow_rl"
android:layout_toRightOf="@+id/dial_close_rl"
android:background="@android:color/holo_green_light" >
<ImageView
android:id="@+id/dialpad_call_imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@android:drawable/ic_menu_call" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/dial_close_rl"
android:layout_width="60dp"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="@+id/dialpad_collapse_imageView"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_action_expand" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/dial_overflow_rl"
android:layout_width="60dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="@+id/dialpad_overflow_imageView"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_action_overflow" />
</RelativeLayout>
</RelativeLayout>
<GridView
android:id="@+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/dialpad_bottom_rl"
android:gravity="center"
android:numColumns="3" >
</GridView>
<RelativeLayout
android:id="@+id/dial_num_edt_rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/gridView1"
android:layout_above="@+id/gridView1"
android:layout_marginBottom="20dp"
android:layout_marginTop="189dp" >
<EditText
android:id="@+id/dial_pad_num_editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/backspace_imageView"
android:ems="10"
android:hint="Enter number" >
<requestFocus />
</EditText>
<ImageView
android:id="@+id/backspace_imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:src="@drawable/ic_action_backspace" />
</RelativeLayout>
</RelativeLayout>
grid_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/grid_num_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:text="2"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="30dp" />
<TextView
android:id="@+id/grid_letter_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/grid_num_textView"
android:paddingLeft="5dp"
android:text="abc"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
</RelativeLayout>
我不知道你的布局是怎样的,所以我在这里写了一个例子,希望对你有帮助。
这里的关键是容器布局中的 android:animateLayoutChanges="true" 。
我假设你的 "enter number" 是我的 tv_b,键盘是 tv_a.
布局如下:
activity_test.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<Button
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/btn_animate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Animate" />
<TextView
android:id="@+id/tv_a"
android:layout_centerHorizontal="true"
android:layout_above="@+id/btn_animate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABCCC" />
<TextView
android:id="@+id/tv_b"
android:layout_above="@+id/tv_a"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABCCD" />
</RelativeLayout>
和activity代码:
MainActivity.java
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
Button btnAnimate = (Button) findViewById(R.id.btn_animate);
final TextView tva = (TextView) findViewById(R.id.tv_a);
final TextView tvb = (TextView) findViewById(R.id.tv_b);
btnAnimate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (tva.getVisibility() == View.VISIBLE) {
tva.setVisibility(View.GONE);
} else {
tva.setVisibility(View.VISIBLE);
}
}
});
}
}
单击“动画”按钮时您将看到动画。
res/anim/scale.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="100%"
android:pivotY="100%"
android:toXScale="1.0"
android:toYScale="0.0" />
</set>
在单击按钮时为该布局使用此缩放动画,如下所示:
Animation animation=AnimationUtils.loadAnimation(activity, R.anim.scale);
animation.setFillAfter(true);
gridView.startAnimation(animation);
我想在键盘折叠图像点击时隐藏我的键盘,并为我的拨号盘输入数字相对布局设置为底部呼叫布局的上部
但我想为我的输入数字编辑文本布局设置动画以放置在底部布局上,请任何人帮助我。
这是我的代码
public class MainActivity extends ActionBarActivity {
private GridView gridView;
private TextView grid_num_tv;
private EditText phone_num_edt;
private RelativeLayout gridView_collapse_rl, dialPad_overflow_rl, dialPad_num_edt_rl;
private ImageView dialPad_collapse_iv;
static final String[] GRID_NUM = new String[] {
"1", "2", "3",
"4", "5", "6",
"7" ,"8", "9" ,
"*", "0", "#"};
static final String[] GRID_LETTERS = new String[] {
" ", "abc", "def",
"ghi", "jkl", "mno",
"pqrs" ,"tuv", "wxyz" ,
" ", "+", " "};
Context context;
ArrayList<GridListDataModel> myGridList = new ArrayList<GridListDataModel>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = (GridView) findViewById(R.id.gridView1);
phone_num_edt = (EditText) findViewById(R.id.dial_pad_num_editText);
gridView_collapse_rl = (RelativeLayout) findViewById(R.id.dial_close_rl);
dialPad_overflow_rl = (RelativeLayout) findViewById(R.id.dial_overflow_rl);
dialPad_collapse_iv = (ImageView) findViewById(R.id.dialpad_collapse_imageView);
dialPad_num_edt_rl = (RelativeLayout) findViewById(R.id.dial_num_edt_rl);
gridView.setVisibility(View.VISIBLE);
gridView.setAdapter(new CustomGridAdapter(this, GRID_NUM));
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
grid_num_tv = (TextView) view.findViewById(R.id.grid_num_textView);
Toast.makeText(getApplicationContext(), grid_num_tv.getText(), Toast.LENGTH_SHORT).show();
}
});
gridView_collapse_rl.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(gridView.isShown()){
dialPad_collapse_iv.setImageResource(R.drawable.ic_action_collapse);
gridView.setVisibility(View.INVISIBLE);
}else{
dialPad_collapse_iv.setImageResource(R.drawable.ic_action_expand);
gridView.setVisibility(View.VISIBLE);
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml 是我的主要布局 xml 文件
<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.gridviewdemo.MainActivity" >
<RelativeLayout
android:id="@+id/dialpad_bottom_rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<RelativeLayout
android:layout_width="60dp"
android:layout_height="45dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_toLeftOf="@+id/dial_overflow_rl"
android:layout_toRightOf="@+id/dial_close_rl"
android:background="@android:color/holo_green_light" >
<ImageView
android:id="@+id/dialpad_call_imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@android:drawable/ic_menu_call" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/dial_close_rl"
android:layout_width="60dp"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="@+id/dialpad_collapse_imageView"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_action_expand" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/dial_overflow_rl"
android:layout_width="60dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="@+id/dialpad_overflow_imageView"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_action_overflow" />
</RelativeLayout>
</RelativeLayout>
<GridView
android:id="@+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/dialpad_bottom_rl"
android:gravity="center"
android:numColumns="3" >
</GridView>
<RelativeLayout
android:id="@+id/dial_num_edt_rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/gridView1"
android:layout_above="@+id/gridView1"
android:layout_marginBottom="20dp"
android:layout_marginTop="189dp" >
<EditText
android:id="@+id/dial_pad_num_editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="@+id/backspace_imageView"
android:ems="10"
android:hint="Enter number" >
<requestFocus />
</EditText>
<ImageView
android:id="@+id/backspace_imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:src="@drawable/ic_action_backspace" />
</RelativeLayout>
</RelativeLayout>
grid_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/grid_num_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:text="2"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="30dp" />
<TextView
android:id="@+id/grid_letter_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/grid_num_textView"
android:paddingLeft="5dp"
android:text="abc"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
</RelativeLayout>
我不知道你的布局是怎样的,所以我在这里写了一个例子,希望对你有帮助。 这里的关键是容器布局中的 android:animateLayoutChanges="true" 。 我假设你的 "enter number" 是我的 tv_b,键盘是 tv_a.
布局如下:
activity_test.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<Button
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/btn_animate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Animate" />
<TextView
android:id="@+id/tv_a"
android:layout_centerHorizontal="true"
android:layout_above="@+id/btn_animate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABCCC" />
<TextView
android:id="@+id/tv_b"
android:layout_above="@+id/tv_a"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABCCD" />
</RelativeLayout>
和activity代码: MainActivity.java
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
Button btnAnimate = (Button) findViewById(R.id.btn_animate);
final TextView tva = (TextView) findViewById(R.id.tv_a);
final TextView tvb = (TextView) findViewById(R.id.tv_b);
btnAnimate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (tva.getVisibility() == View.VISIBLE) {
tva.setVisibility(View.GONE);
} else {
tva.setVisibility(View.VISIBLE);
}
}
});
}
}
单击“动画”按钮时您将看到动画。
res/anim/scale.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="100%"
android:pivotY="100%"
android:toXScale="1.0"
android:toYScale="0.0" />
</set>
在单击按钮时为该布局使用此缩放动画,如下所示:
Animation animation=AnimationUtils.loadAnimation(activity, R.anim.scale);
animation.setFillAfter(true);
gridView.startAnimation(animation);