2016-06-08 8 views
5

मैं TextInputLayout का उपयोग कर रहा हूं और जिसमें मैंने ड्रॉइंग लेफ्ट सेट किया है और जब मैं एडिटेक्स्ट पर क्लिक करता हूं तो लेबल पहले से ही फ़्लोट हो रहा है लेकिन मैं लेबल के साथ बाएं ड्रॉइंग को भी फ़्लोट करना चाहता हूं। मैं कैसे प्राप्त कर सकता हूं, संलग्न छवि को देख सकता हूं ...TextInputLayout में (संकेत) लेबल के साथ बाएं खींचने योग्य कैसे फ़्लोट करें?

अभी जब मैं "शीर्षक" पर क्लिक करता हूं तो केवल लीबल फ़्लोटिंग हो रहा है, लेकिन मैं चाहता हूं कि दोनों ध्यान केंद्रित करते समय "बाएं" और "लेबल" फ़्लोट करना चाहिए। और क्लिक करने से पहले यह "सेवा दिनांक" जैसी सामान्य रेखा दिखाई देगा।

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(); 
      } 
     } 
    }); 

और मेरे एनीमेशन शीर्ष

<?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> 
पर छवि दृश्य फेंक देगा

और इसे स्थापित करके मुझे अभी मिला है, लेकिन पैडिंग लेफ्ट = "35 डीपी" देखें, मैं इसे पहली स्थिति में देखना चाहता हूं जहां "शीर्षक" दिख रहा है, मेरा मतलब है कि वहां नहीं होना चाहिए पैडिंग बनें लेकिन अगर मैं को पैडिंग लेफ्टिंग फ्लोटिंग कार्यक्षमता हानि हटा दूंगा।

enter image description here

+1

आप लिखने के लिए की आवश्यकता होगी इसके लिए आपका अपना कार्यान्वयन। TextInputLayout लेआउट के एनिमेटेड टेक्स्ट को आकर्षित करने के लिए [CollapsingTextHelper] का उपयोग करता है (https://android.googlesource.com/platform/frameworks/support/+/6ba61c5/design/src/android/support/design/widget/CollapsingTextHelper.java) कक्षा कैनवास। अनुकूलन के लिए कोई जगह नहीं है क्योंकि यह कक्षा आंतरिक है। –

+0

@ एसडी। मैंने कस्टमाइज़ करने की कोशिश की लेकिन अब मुझे केवल थोड़ी सी समस्या है, मैं बाएं पैडिंग को हटाना चाहता हूं, ताकि उपयोगकर्ता बहुत प्रारंभ कर सकें, छवि –

+0

देखें, एनीमेशन शुरू होने पर बाएं खींचने योग्य को हटाएं/सेट करें। [TextInputLayout] (https://android.googlesource.com/platform/frameworks/support/+/6ba61c5/design/src/android/support/design/widget/TextInputLayout.java) में टेक्स्ट लिस्टनर इसमें संपादन टेक्स्ट की निगरानी करता है, और यहां से यह एनीमेशन आग लगती है। –

उत्तर

3

इस कोशिश ...

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> 
+0

कृपया मेरा संपादित प्रश्न देखें, मैं ठीक नहीं हो रहा हूं, छवि देखें। –

संबंधित मुद्दे