1

我正在使用纹理视图上的相机编写应用程序。首先,摄像头是在一个小窗口中,当你点击按钮时应该拉伸到全屏。

小窗

全屏模式

当textureview在全屏模式下就好了。但是当我设置为 textureview 固定高度时,来自相机的图片会被压缩。如何使图像正确缩放?

按钮 onClick 监听器

ViewGroup.LayoutParams params = mTextureView.getLayoutParams();
if(!isFullScreen) {
    isFullScreen = true;
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    params.width = dm.widthPixels;
    params.height = dm.heightPixels;
    mTextureView.setLayoutParams(params);
}else{
    isFullScreen = false;
    params.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, getResources().getDisplayMetrics());
    mTextureView.setLayoutParams(params);
}
4

1 回答 1

0

我通过使用不错的库https://github.com/umano/AndroidSlidingUpPanel创建了它

<com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    sothree:umanoDragView="@+id/dragView"
    sothree:umanoInitialState="collapsed"
    sothree:umanoPanelHeight="200dp"
    sothree:umanoParalaxOffset="0dp">

    <!-- MAIN CONTENT -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    <!-- SLIDING LAYOUT -->
    <LinearLayout
        android:id="@+id/dragView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/black"
        android:clickable="true"
        android:focusable="true"
        android:orientation="vertical">

        <TextureView
            android:id="@+id/texture_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>

</com.sothree.slidinguppanel.SlidingUpPanelLayout>

并为相机滚动添加视差

 slidingPanel.setPanelSlideListener(new SlidingUpPanelLayout.PanelSlideListener() {
        @Override
        public void onPanelSlide(View panel, float slideOffset) {
            dragView.setPadding(0, (int) (parallaxOffset * slideOffset - parallaxOffset), 0, 0);
        }

        @Override
        public void onPanelExpanded(View panel) {
            Log.i(TAG, "onPanelExpanded");
            resizeBtn.setSelected(true);
        }

        @Override
        public void onPanelCollapsed(View panel) {
            Log.i(TAG, "onPanelCollapsed");
            resizeBtn.setSelected(false);
        }

        @Override
        public void onPanelAnchored(View panel) {
            Log.i(TAG, "onPanelAnchored");
        }

        @Override
        public void onPanelHidden(View panel) {
            Log.i(TAG, "onPanelHidden");
        }
    });
}
于 2015-04-14T07:54:14.013 回答