2016-04-12 17 views
0

丸みを帯びたサーフェイスビューを作成しようとしています。私はたくさん検索しましたが、良い解決策を見つけることができませんでした。私が今やっているのは、SurfaceViewをFrameLayoutに入れ、次にPNGマスク、またはシェイプxml描画可能なものの上に別のViewを配置しました。ここにあります丸みを帯びたサーフェスビューの作成方法

<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> 

しかし、これは良い解決策ではありませんし、また完全には機能しません。サーフェスビューを丸みのある形にカスタマイズしたいどんな助けでも大変に感謝します。ありがとう:)

+0

HTTPをコーディング

app:cardCornerRadius="10dp" app:cardPreventCornerOverlap="false" 

乾杯ハッピーカードビュー内でこの2行を使用するためにGradleのファイルにこれを追加することを忘れないでください。 //stackoverflow.com/questions/26074784/how-to-make-a-view-in-android-withrounded-corners ...試してみてください。SurfaceViewにFrameLayoutを変更してください –

+0

ありがとうございました。 @sunilsunnyあなたはこれを使って任意のビューを丸めることができますが、サーフェイスビューは使用できません。私はすでにそれを試しました:) –

+0

@TashenJazbi:これの解決策を見つけましたか?私は同じ実装の問題で立ち往生しています。ソリューションを投稿してください。ありがとう – Neha

答えて

3

を試してみてください。

SurfaceViewには、サーフェスとビューという2つの部分があります。 Viewパーツは他のViewと同じように機能します。デフォルトでは、透明な「穴」として機能し、レイアウト内にウィンドウを作成します。すべてのビューは、アプリケーションによって単一のレイヤーにレンダリングされます。

Surfaceパートは、(SurfaceのZオーダーを明示的に変更しない限り)Viewレイヤーの背後にある別のレイヤーです。そのため、Viewレイヤーの透明部分を「表示」する場所のみが表示されます。 Viewレイヤーを描画してSurfaceの一部をマスクすることはできますが、Surfaceレイヤー自体のシェイプを変更することはできません。レイヤーは長方形です。

多くの場合、SurfaceViewの代わりにTextureViewを使用できます。 TextureViewは、アプリケーションによってViewレイヤーにレンダリングされるため、柔軟性が高くなりますが、SurfaceViewよりも効率が悪い可能性があります。

詳細については、Android graphics architecture docをご覧ください。

+0

あなたの答えは正解としてそ​​れを受け入れることは妥当と聞こえる。ご参加ありがとうございます :) –

0

はあなたがSurfaceViewの表面の形状を変更することはできません。この

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" > 
    <gradient android:startColor="#FFFF0000" android:endColor="#80FF00FF" 
     android:angle="270"/> 
</shape> 



<SurfaceView 
     android:background="@drawable/circle" 
     android:id="@+id/surfaceView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 
+0

SurfaceViewには影響しません。私はすでにそれを試しました:) –

1

少しハックします。あなたの表面をカードビューの内側に置きます。

<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> 

がCardViewまた

compile 'com.android.support:cardview-v7:25.0.1' 

関連する問題