我用兩個imageViews而不是FragmentLayout實現了這個例子。它正在像你想要的那樣崩潰和擴大。有兩個按鈕可以展開和摺疊。
這些是我的java類,xml和動畫。
Java類
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class expandAndCollapes extends Activity{
boolean isExpanded=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.extend_lay);
Button expand=(Button)findViewById(R.id.button1);
Button collapse=(Button)findViewById(R.id.button2);
final ImageView image1=(ImageView)findViewById(R.id.imageView1);
final ImageView image2=(ImageView)findViewById(R.id.imageView2);
expand.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(!isExpanded){
image1.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.scale_out));
image2.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down));
isExpanded=true;
}
}
});
collapse.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(isExpanded){
image1.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.scale_in));
image2.startAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up));
isExpanded=false;
}
}
});
}
}
XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="expand" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/button1"
android:text="collapse" />
<LinearLayout
android:id="@+id/inner_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/button1"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:src="@drawable/ic_launcher" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</RelativeLayout>
scale_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator">
<scale
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="0%"
android:toXScale="1"
android:toYScale="4" >
</scale>
</set>
scale_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator">
<scale
android:duration="1000"
android:fromXScale="1"
android:fromYScale="4"
android:pivotX="50%"
android:pivotY="0%"
android:toXScale="1"
android:toYScale="1" >
</scale>
</set>
slide_down.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator" >
<translate
android:duration="1000"
android:fromXDelta="0%"
android:fromYDelta="0%"
android:toXDelta="0%"
android:toYDelta="100%" />
</set>
滑動up.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:interpolator="@android:anim/linear_interpolator" >
<translate
android:duration="1000"
android:fromXDelta="0%"
android:fromYDelta="100%"
android:toXDelta="0%"
android:toYDelta="0%" />
</set>
什麼我有縮放第一視圖1〜4和向下滑動第二個視圖。 它應該是4,因爲你的佈局權重是1和3(1 + 3 = 4)。希望這有助於你得到一些想法。
這工作,但上方的看法(在我的情況下mapFragment)拉伸。所以地圖實際上並沒有調整大小,而是延伸了。 – devha