我在屏幕底部有一个带工具栏的活动。工具栏有一个相机按钮。当用户单击该按钮时,必须出现摄像机视图。它必须从此活动的底部出现,在工具栏下,填充最多1/3的屏幕。我为相机创建了SurfaceView。但由于
,无法将其设置在工具栏下方alignParentBottom = “真”
如何做这个外观?
这是我的布局
<SurfaceView
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<RelativeLayout
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#f4f5f7">
<ImageButton
android:id="@+id/btn_camera"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#f4f5f7"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="@drawable/camera59" />
...
</RelativeLayout>
答案 0 :(得分:0)
使用动画LinearLayout解决它。
Camera_Activity.class
public class Camera_Activity extends AppCompatActivity {
ImageButton btn_camera;
ImageButton btn_mic;
SurfaceView sv;
LinearLayout show_video;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.anim_footer);
show_video = (LinearLayout) findViewById(R.id.show_video);
btn_camera = (ImageButton) findViewById(R.id.btn_camera);
btn_mic = (ImageButton) findViewById(R.id.btn_mic);
sv = (SurfaceView) findViewById(R.id.camera_view);
btn_camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (sv.getVisibility() == View.GONE) {
sv.setVisibility(View.VISIBLE);
final Animation show = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.show_video);
show_video.startAnimation(show);
}
}
});
btn_mic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (sv.getVisibility() == View.VISIBLE) {
final Animation hide = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.hide_video);
hide.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
sv.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
show_video.startAnimation(hide);
}
}
});
}
}
anim_footer.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/parent"
android:background="@drawable/gradient"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.MainActivity">
<LinearLayout
android:id="@+id/show_video"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#80000000">
<ImageButton
android:id="@+id/btn_camera"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="@android:drawable/ic_media_play" />
<ImageButton
android:id="@+id/btn_mic"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="@android:drawable/ic_delete" />
<ImageButton
android:id="@+id/btn_cat"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toLeftOf="@id/btn_mic"
android:layout_toStartOf="@id/btn_mic"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="@android:drawable/ic_lock_lock" />
</RelativeLayout>
<SurfaceView
android:visibility="gone"
android:background="@drawable/photo"
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="300dp" />
</LinearLayout>
</RelativeLayout>
动画:
show_video.xml
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/accelerate_cubic"
android:startOffset="150"
android:fromYDelta="86%"
android:toYDelta="0"
android:fillAfter="true"
android:duration="2000"/>
hide_video.xml
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/bounce"
android:fromYDelta="0"
android:toYDelta="85%"
android:duration="1500"/>