gpt4 book ai didi

android - 如何在 TextInputLayout 中使用(提示)标签 float 左侧可绘制对象?

转载 作者:行者123 更新时间:2023-11-29 01:19:39 25 4
gpt4 key购买 nike

我正在使用 TextInputLayout,我在其中设置了一个 drawableLeft,当我单击 edittext 时,标签已经向上 float ,但我也想用标签 float 左侧的可绘制对象。我怎样才能实现,看附图...

现在,当我单击“标题”时,只有 leble float ,但我希望两者在聚焦时都应该 float “leftdrawable”和“label”。在点击之前,它看起来像一条正常的线,如“服务日期”。

enter image description here

我的代码在下面..

<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/input_layout_cardnum"
>
<ImageView
android:id="@+id/imgLeft"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="bottom"
android:src="@mipmap/ic_launcher"
android:layout_marginBottom="10dp"
/>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_cardnums"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="@+id/cardnumEditTexst"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="255"
android:singleLine="true"
android:hint="hello"
android:drawableLeft="@null"
android:paddingLeft="35dp"
/>
</android.support.design.widget.TextInputLayout>
</FrameLayout>

在我的代码中,我在 onFocus 上设置了一个动画,所以它会在标签上显示

  final Animation animation = AnimationUtils.loadAnimation(this,R.anim.anims);
final ImageView imgLeft = (ImageView) findViewById(R.id.imgLeft);

final EditText et = (EditText) findViewById(R.id.cardnumEditTexst);
et.setOnFocusChangeListener(new View.OnFocusChangeListener()
{
@Override
public void onFocusChange(View v, boolean hasFocus)
{
if (hasFocus)
{
if (et.getText().length() == 0)
{
imgLeft.startAnimation(animation);
}
} else
{
if (et.getText().length() == 0)
imgLeft.clearAnimation();
}
}
});

我的动画会将 ImageView 放在顶部

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:duration="200"
android:interpolator="@android:interpolator/linear"
>
<scale
android:fromXScale="0%"
android:fromYScale="0%"
android:toXScale="60%"
android:toYScale="60%"
android:pivotX="50%"
android:pivotY="50%"
/>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:startOffset="100"
android:fromYDelta="0%"
android:toYDelta="-80%"/>

</set>

通过设置这个,我得到了,现在可以 float 了,但是看到 paddingLeft="35dp",我想从第 0 个位置开始,在第一张显示“标题”的图片中看到,我的意思是不应该有填充,但如果我将删除 paddingLeft float 功能损失。

enter image description here

最佳答案

试试这个...

final Animation animation = AnimationUtils.loadAnimation(this, R.anim.anims);
final ImageView imgLeft = (ImageView) findViewById(R.id.imgLeft);

findViewById(R.id.cardnumEditTexst).setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
imgLeft.startAnimation(animation);
} else {
imgLeft.clearAnimation();
}
}
});

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:fillAfter="true"
android:interpolator="@android:interpolator/linear">

<scale
android:fromXScale="0%"
android:fromYScale="0%"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="60%"
android:toYScale="60%" />

<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="0%"
android:startOffset="100"
android:toYDelta="-80%" />

</set>

然后像这样设置你的布局...

<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/input_layout_cardnum">

<ImageView
android:id="@+id/imgLeft"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="bottom"
android:src="@mipmap/ic_launcher"
android:layout_marginBottom="10dp" />

<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout_cardnums"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/cardnumEditTexst"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="255"
android:singleLine="true"
android:hint="hello"
android:drawableLeft="@null"
android:paddingLeft="35dp" />
</android.support.design.widget.TextInputLayout>
</FrameLayout>

关于android - 如何在 TextInputLayout 中使用(提示)标签 float 左侧可绘制对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37694064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com