2016-04-26 166 views
0

我正在制作一个有卡片角落的对话框。但我不能使它看起来像一张卡片。我可以制作角落,但仍然位于对话框上显示的红色半径颜色的上方。我尝试了一切,但我无法使它工作。有人能帮我吗?我的主要布局是cardView,并将我的形状布局放置在线性布局的背景中。 enter image description here卡片看起来布局

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
<solid android:color="#FFFFFF"/> 
<stroke 
    android:width="6dip" 
    android:color="#f45"/> 
<corners android:radius="15dip"/> 
<padding 
    android:bottom="0dip" 
    android:left="0dip" 
    android:right="0dp" 
    android:top="0dip"/> 

enter image description here

<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="250dp" 
android:layout_height="wrap_content" 
android:baselineAligned="false" 
android:orientation="vertical" 
android:paddingLeft="10dp" 
android:paddingRight="10dp"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:background="@drawable/layout_bg" 
    > 

    <TextView 
     android:id="@+id/textView7" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="15dp" 
     android:text="Bits Please" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:foreground="@android:color/transparent"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0.5dp" 
     android:layout_alignParentEnd="false" 
     android:layout_alignParentStart="false" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_weight="1" 
     android:background="#030202" 
     android:orientation="horizontal"> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/textView8" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp" 
      android:text="text"/> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:paddingBottom="10dp" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp"> 

     <TextView 
      android:id="@+id/textView9" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="15dp" 
      /> 

     <TextView 
      android:id="@+id/textView10" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="15dp" 
      /> 

     <TextView 
      android:id="@+id/textView11" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="15dp" 
      /> 
    </LinearLayout> 
</LinearLayout> 

+0

可能的重复http://stackoverflow.com/questions/10795078/dialog-with-transparent-background-in-android –

回答

0

的这样的事情为我工作,但我只是说这行代码到CardView布局 - >应用:cardCornerRadius =“量”

没有背景,主题,样式或任何需要的。希望这可以帮助别人

,这在活动代码:

dialog.getWindow()setBackgroundDrawable(新ColorDrawable(Color.TRANSPARENT))。

1

利用这一点,随着你的代码 -

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 

,并添加透明背景和基础d在cardview太 -

<android.support.v7.widget.CardView 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:layout_width="250dp" 
android:layout_height="wrap_content" 
android:baselineAligned="false" 
android:orientation="vertical" 
android:paddingLeft="10dp" 
android:paddingRight="10dp" 
android:background="@android:color/transparent" > 
+0

已经尝试过,不起作用 – hyrulelink16

+0

请检查现在。 –

+0

仍然没有进展。顺便说一句,这是代码: [code] public void showAboutAlert(){ final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.about_us_layout); dialog.getWindow()。setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); dialog.show(); } [code] 尝试移动setBackgroundDrawable围绕代码,仍然没有进展。 – hyrulelink16