Android的:如何将一个动画形象一个EditText里面,我们可以显示和隐藏 [英] Android: How to place an animated image inside an EditText that we can show and hide

查看:142
本文介绍了Android的:如何将一个动画形象一个EditText里面,我们可以显示和隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想补充一个动画微调的的EditText观点的权利。并以编程方式显示/隐藏它。

I am trying to add an animated spinner inside a EditText view to the right. And programmatically show/hide it.

我已经通过引入线性插值旋转产生的动画微调:

I have created the animated spinner by introducing a linear interpolation rotation:

* RES /动画/ rotate_forever.xml *

<?xml version="1.0" encoding="UTF-8"?>
<rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:interpolator="@anim/linear_interpolator"
    android:duration="1200" />

RES /布局/ main.xml中

res/layout/main.xml

 <LinearLayout android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:paddingRight="6dip"
      android:paddingLeft="6dip"
      android:orientation="horizontal" 
      android:background="@drawable/header_gradient" >
  <EditText android:id="@+id/search_text"
       android:layout_height="fill_parent"
       android:layout_width="fill_parent"
       android:layout_weight="1"
       android:singleLine="true"
       android:focusable="true" />
  <ImageView android:id="@+id/search_spinner"
      android:gravity="center_vertical|right"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src="@drawable/spinner_black"/>
 </LinearLayout>

我触发动画的方式是通过编程而工作,我看到了EditView中左侧和ImageView的旋转右侧(因为我不知道其他方式)

The way I trigger an animation is programmatically which works, I see the EditView on the left and the ImageView spinning on the right (because I have no idea otherwise)

ImageView searchSpinner = (ImageView) findViewById(R.id.search_spinner);
Animation spinnerAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate_forever);
searchSpinner.startAnimation(spinnerAnimation);

我的问题是这样的:

My questions are this:

  1. 如何将ImageView的 在EditText上就远远内 对。因此,它会出现内部不 外面。(我想我可以的地方 一个机器人:drawableRight,但 没有工作。
  2. 如何 隐藏/显示ImageView的(微调),我 尝试设置视图的 隐蔽性,通过做 searchSpinner.setVisibility(View.INVISIBLE); 但没有奏效。
  1. How can I place the ImageView inside the EditText on the far right. So it will appear inside not outside. (I thought I can just place a android:drawableRight, but that didn't work.
  2. How can I hide/show the ImageView (spinner), I tried setting the View's invisibility, by doing searchSpinner.setVisibility(View.INVISIBLE); but that didn't work.

谢谢你,如果你有更好的想法如何处理这个,我听:)

Thanks, if you have any better ideas how to approach this, I am listening :)

推荐答案

通过你已经做的工作​​,我认为最简单的答案会是你的LinearLayout更改为RelativeLayout的,这样就可以在设置alignParentRight ImageView的,并根据需要添加paddingRight。

With the work that you've already done, I think the easiest answer would be to change your LinearLayout to a RelativeLayout, so that you can set alignParentRight on the ImageView and add paddingRight as needed.

另一种方法是创建一个自定义视图组件:的http:// developer.android.com/guide/topics/ui/custom-components.html

Another option is to create a custom view component: http://developer.android.com/guide/topics/ui/custom-components.html

这篇关于Android的:如何将一个动画形象一个EditText里面,我们可以显示和隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆