我正在使用textureview上的相机编写应用程序。 首先,相机在一个小窗口中,当你点击按钮时应该拉伸到全屏。
当全屏模式下的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);
}
答案 0 :(得分: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");
}
});
}