Tas*_*zbi 1 android surfaceview
我正在尝试制作圆形的表面视图.我搜索了很多,但我找不到一个好的解决方案.我现在正在做的是,我将SurfaceView放入FrameLayout,然后将另一个View放在它上面,或者使用PNG蒙版,或者使用形状xml drawable.这里是
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="140dp"
android:layout_height="140dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#000"
android:orientation="vertical"
android:visibility="visible" >
<FrameLayout
android:id="@+id/videorecordview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight=".2" >
<SurfaceView
android:id="@+id/surfaceView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/rounded"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
但这不是一个好的解决方案,也不是完美的.我想将surfaceview自定义为圆形.任何帮助将非常感激.谢谢 :)
ral*_*abb 12
有点破解.将表面视图放在卡片视图中.
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_normal"
app:cardCornerRadius="10dp"
app:cardPreventCornerOverlap="false">
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/margin_normal" />
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
不要忘记将其添加到您的gradle文件以使用CardView
compile 'com.android.support:cardview-v7:25.0.1'
Run Code Online (Sandbox Code Playgroud)
另外这两行内部卡片视图
app:cardCornerRadius="10dp"
app:cardPreventCornerOverlap="false"
Run Code Online (Sandbox Code Playgroud)
干杯快乐的编码
您无法更改SurfaceView的Surface的形状。
SurfaceView有两部分,Surface和View。视图部分的工作方式与其他任何视图一样。默认情况下,它只是充当透明的“孔”,在布局中创建一个窗口。应用程序将所有视图呈现到单个图层上。
Surface部件是一个单独的层,位于View层后面(除非您显式更改Surface的Z顺序),因此您只能在它“显示” View层的透明区域的地方看到它。您可以在“视图”层上进行绘制以遮盖“表面”的某些部分,但不能更改“表面”层本身的形状。图层为矩形。
在许多情况下,可以使用TextureView代替SurfaceView。TextureView提供了更大的灵活性,因为它是由应用程序渲染到View图层上的,但效率却不如SurfaceView。
可以在Android 图形体系结构文档中找到更多信息。
归档时间: |
|
查看次数: |
3814 次 |
最近记录: |