2012-02-20 10 views
11

Mam cztery EditText z innym tłem. Wygląda to tak: enter image description hereZmiana wysokości i szerokości EditText w środowisku wykonawczym z pewną animacją

Chcę zakryć cały ekran, gdy EditText jest zaznaczony przy pomocy tego EditText. W tym celu muszę zmienić szerokość i wysokość EditText z pewną animacją w Runtime.

Po wybraniu Powinno to wyglądać tak: enter image description here

Jak mogę zmienić rozmiar EditText z animacji w czasie wykonywania?

+0

tak, trzeba użyć animacji aby EditText zajmują layoutu wypełnienia rodzica, gdy wniosek koncentruje się na nim. dobrze? –

+0

@Raman tak. Próbowałem z twoimi ans, Ale to nie było to. – asish

Odpowiedz

4

Nie jestem pewien, czy można to zrobić za pomocą Animations. W widoku android zajmuje całą przestrzeń przed zakończeniem animacji, więc zobaczysz, że inne editTexts znika i wybiera jeden powoli rośnie. Tutaj jest szorstka przykładem, jak to zrobić bez standart animacji, ale zmiana wagi w osobnym wątku:

układ:

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

iw kodzie dodać działania dotyczące zmiany ostrości:

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

robię nie wiem, czy jest to możliwe, ale w tym przykładzie możesz dodać trochę więcej ruchów całkiem łatwo.

zrobić nie polecam używać jej produkcję, jeśli tylko masz jakieś inne opcje.

+0

Zobacz moją zredagowaną odpowiedź – Jin35

0

Próbowałem wyjaśnić moja logika dla swojego problemu ... mam nadzieję, że tak będzie pracować dla Ciebie ..

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

To było to, co znałem, mój drogi przyjacielu ... Przepraszam, że mogę pomóc ci się rozwijać ... ale nadal .... spróbuj z tą koncepcją dla Animacji ... to jest właściwa droga aby zmienić rozmiar w czasie wykonywania, a także byłoby pomocne w zmianie rozmiaru animacji ... –

6

ODPOWIEDŹ AKTUALIZACJA:

użyć tego kodu w odkształcalne /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" /> 

i ustawić animację do edycji tekstu przy użyciu:

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); 
Powiązane problemy