2011-08-20 12 views
2

두 레이아웃을 하나로 병합 할 수 있습니까? 첫 번째 레이아웃에 사용자 이름과 암호의 두 TextView가 있고 두 번째 레이아웃에 두 개의 EditText가 세로로 있다고 가정합니다. 이 두 레이아웃을 병합 한 후 최종 레이아웃에는 TextView와 EditText의 두 행이 포함됩니다.두 레이아웃을 하나로 병합

오 왼쪽의 한 가지는 왼쪽에서 오른쪽으로 첫 번째 레이아웃 이동을 병합 할 때 두 번째 레이아웃이 오른쪽에서 왼쪽으로 이동하는 것입니다.

답변

1

TranslateAnimation을 적용하여이 작업을 수행 할 수 있습니다. 애니메이션을 적용하면 두 개의 레이아웃이 하나로 합쳐진 것처럼 보입니다. 다음 코드가 도움이되기를 바랍니다.

layout.xml ...

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
<Button 
android:id="@+id/btn1" 
android:text="Button 1" 
android:layout_width="fill_parent" 
android:layout_height="45dip" 
android:layout_marginTop="10dip" 
/> 

<Button 
android:id="@+id/btn2" 
android:text="Button 2" 
android:layout_width="fill_parent" 
android:layout_height="45dip" 
android:layout_marginTop="10dip" /> 

<Button 
android:id="@+id/btn3" 
android:text="Button 3" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="10dip" 
/> 

<Button 
android:id="@+id/btn4" 
android:text="Button 4" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:layout_marginTop="10dip" 
/> 

MyActivity.java

Button b1, b2, b3, b4; 
    TranslateAnimation left, right; 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    left = new TranslateAnimation(-480, 10, 0, 10); 
    right= new TranslateAnimation(480, 10, 0, 10); 

    left.setDuration(2000); 
    right.setDuration(2000); 

    left.setRepeatCount(1); 
    right.setRepeatCount(1); 

    b1 =(Button)findViewById(R.id.btn1); 
    b2 =(Button)findViewById(R.id.btn2); 
    b3 =(Button)findViewById(R.id.btn3); 
    b4 =(Button)findViewById(R.id.btn4); 

    b1.startAnimation(left); 
    b2.startAnimation(right); 
    b3.startAnimation(left); 
    b4.startAnimation(right); 
관련 문제