2012-02-20 18 views
11

के साथ रनटाइम पर EditText ऊंचाई और चौड़ाई बदलना मेरे पास विभिन्न पृष्ठभूमि के साथ चार संपादन टेक्स्ट हैं। ऐसा लगता है: enter image description hereकुछ एनीमेशन

मैं उस संपादन टेक्स्ट के साथ एक संपादन टेक्स्ट का चयन करते समय पूर्ण स्क्रीन को कवर करना चाहता हूं। इसके लिए मुझे रनटाइम पर कुछ एनीमेशन के साथ एडिटटेक्स्ट चौड़ाई और ऊंचाई को बदलने की जरूरत है।

चयनित होने पर यह इस तरह दिखना चाहिए: enter image description here

मैं कैसे EditText आकार रनटाइम पर एनीमेशन के साथ बदल सकते हैं?

+0

हां, तो आप edittext लेआउट के भरण माता पिता पर कब्जा जब अनुरोध यह पर ध्यान केंद्रित करने के लिए एनीमेशन का उपयोग करने की आवश्यकता है। सही? –

+0

@ रमन हां.मैंने आपके उत्तर के साथ प्रयास किया है, लेकिन ऐसा नहीं था। – asish

उत्तर

4

मुझे यकीन नहीं है कि यह Animations के साथ किया जा सकता है। एंड्रॉइड व्यू में एनीमेशन समाप्त होने से पहले सभी जगह लेती है, इसलिए आप देखेंगे कि अन्य संपादन टेक्स्ट गायब हो जाते हैं और धीरे-धीरे बढ़ते हुए चुने जाते हैं। यहाँ किसी न किसी उदाहरण कैसे standart एनिमेशन के बिना यह करने के लिए है, लेकिन है अलग थ्रेड में बदल रहा है वजन:

लेआउट:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    OnFocusChangeListener focusListener = new OnFocusChangeListener() { 
     @Override 
     public void onFocusChange(View v, boolean hasFocus) { 
      if (hasFocus) { 
       LinearLayout parent = (LinearLayout) v.getParent(); 
       EditText forDecresing = null; 
       for (int i = 0; i < parent.getChildCount(); i++) { 
        if (parent.getChildAt(i) != v) { 
         forDecresing = (EditText) parent.getChildAt(i); 
         break; 
        } 
       } 
       LinearLayout pp = (LinearLayout) parent.getParent(); 
       LinearLayout layoutForDecreasing = null; 
       for (int i = 0; i < pp.getChildCount(); i++) { 
        if (pp.getChildAt(i) != parent && pp.getChildAt(i) instanceof LinearLayout) { 
         layoutForDecreasing = (LinearLayout) pp.getChildAt(i); 
         break; 
        } 
       } 
       startAnimation((EditText) v, forDecresing, layoutForDecreasing, parent); 
      } else { 
      } 
     } 
    }; 

    ((EditText) findViewById(R.id.et00)).setOnFocusChangeListener(focusListener); 
    ((EditText) findViewById(R.id.et01)).setOnFocusChangeListener(focusListener); 
    ((EditText) findViewById(R.id.et11)).setOnFocusChangeListener(focusListener); 
    ((EditText) findViewById(R.id.et10)).setOnFocusChangeListener(focusListener); 
} 

public void onBackPressed() { 
    setWeight(findViewById(R.id.et00), 1); 
    setWeight(findViewById(R.id.et01), 1); 
    setWeight(findViewById(R.id.et11), 1); 
    setWeight(findViewById(R.id.et10), 1); 
    setWeight(findViewById(R.id.ll1), 1); 
    setWeight(findViewById(R.id.ll0), 1); 
} 

Thread animationThread; 

private void startAnimation(final EditText forIncreasing, final EditText forDecresing, final LinearLayout layoutForDecreasing, 
     final LinearLayout layoutForIncreasing) { 
    if (animationThread != null) 
     animationThread.interrupt(); 
    animationThread = new Thread(new Runnable() { 
     @Override 
     public void run() { 
      int iterations = 0; 
      int maxIterations = 30; 
      setWeight(forIncreasing, maxIterations - 1); 
      setWeight(layoutForIncreasing, maxIterations - 1); 
      setWeight(forDecresing, maxIterations - 1); 
      setWeight(layoutForDecreasing, maxIterations - 1); 
      while (iterations < maxIterations) { 
       iterations++; 
       setWeight(forIncreasing, maxIterations - 1 + iterations); 
       setWeight(layoutForIncreasing, maxIterations - 1 + iterations); 
       setWeight(forDecresing, maxIterations - 1 - iterations); 
       setWeight(layoutForDecreasing, maxIterations - 1 - iterations); 
       try { 
        Thread.sleep(10); 
       } catch (InterruptedException e) { 
        return; 
       } 
      } 
      animationThread = null; 
     } 
    }); 
    animationThread.start(); 
} 

private void setWeight(final View view, final float weight) { 
    runOnUiThread(new Runnable() { 
     @Override 
     public void run() { 
      LayoutParams params = (LayoutParams) view.getLayoutParams(); 
      params.weight = weight; 
      view.setLayoutParams(params); 
     } 
    }); 
} 

मुझे क्या करना:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<LinearLayout 
    android:id="@+id/ll0" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="horizontal" > 

    <EditText 
     android:id="@+id/et00" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:gravity="top|left" 
     android:text="00" /> 

    <EditText 
     android:id="@+id/et01" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:gravity="top|left" 
     android:text="01" /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/ll1" 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:orientation="horizontal" > 

    <EditText 
     android:id="@+id/et10" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:gravity="top|left" 
     android:text="10" /> 

    <EditText 
     android:id="@+id/et11" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:gravity="top|left" 
     android:text="11" /> 
</LinearLayout> 
</LinearLayout> 

और कोड में बदलने के फोकस पर कार्रवाई जोड़ने यह नहीं पता कि यह आपके लिए संभव है, लेकिन इस उदाहरण में आप कुछ और आंदोलनों को काफी आसान जोड़ सकते हैं।

मैं ऐसा नहीं अनुशंसा करते हैं यह उत्पादन का उपयोग करता है, तो केवल आप कुछ अन्य विकल्प हैं।

+0

मेरा संपादित उत्तर देखें – Jin35

0

मैं आपकी समस्या के लिए मेरे तर्क की व्याख्या करने की कोशिश की है ... मैं तो आशा है कि .. यह आप के लिए काम करेगा

EditText editText = new EditText(this); 
editText.setOnClickListener(new OnClickListener() { 

    public void onClick(){  
     // Before getSize was introduced (in API level 13), you could use 
     // the getWidth and getHeight methods that are now deprecated: 

     Display display = getWindowManager().getDefaultDisplay(); 
     int width = display.getWidth(); 
     int height = display.getHeight(); 

     editText.setWidth(width); 
     editText.setHeight(height); 
    } 
} 
+1

यही वह था जो मैं अपने प्यारे दोस्त को जानता था ... मुझे खेद है कि मैं आपको पोषित करने में मदद कर सकता हूं .... लेकिन फिर भी .... आप एनीमेशन के लिए इस अवधारणा के साथ प्रयास करें ... यह सही तरीका है रनटाइम पर आकार बदलने के लिए और एनीमेशन के आकार को बदलने में सहायक भी होगा ... –

6

उत्तर UPDATED:

उपयोग drawable में इस कोड /animation_sample.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> 
<translate android:fromXDelta="0%" android:toXDelta="100%" android:fromYDelta="0%" android:toYDelta="0%" android:duration="500" /> 

और का उपयोग कर पाठ संपादित करने के लिए एनीमेशन सेट:

Animation anim=AnimationUtils.loadAnimation(this, R.anim.righttoleft); 
editText = (EditText)findViewById(R.id.editText1); 
Display display = getWindowManager().getDefaultDisplay(); 
int width=display.getWidth(); 
int height = display.getHeight(); 
editText.setWidth(width); 
editText.setHeight(height); 

editText.startAnimation(anim); 
संबंधित मुद्दे