【问题标题】:how to make a overlay window in android?如何在android中制作覆盖窗口?
【发布时间】:2013-11-06 21:32:38
【问题描述】:

我正在尝试制作一个如图所示的警报对话框。我试图使用框架布局,但不能让它像图片一样正确。在我当前的布局中,我使用了 imageView 和 textview。

<LinearLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ImageView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src=""/>
        <TextView 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="@strings/text"
        />
    </FrameLayout>
    <!---<other layouts--->
</LinearLayout>

【问题讨论】:

  • 代码中的哪个布局代表错误?
  • @Demand 我试图让它覆盖到另一个活动。像自定义对话框或像图片一样平滑。
  • 您可以使用带有自定义布局的 Toast..
  • @bakriOnFire 你帮了我很多。带有自定义布局的 Toast 成功了 :)

标签: java android


【解决方案1】:

你可能需要看看Crouton library

【讨论】:

    【解决方案2】:

    要显示带有自定义内容的对话框,

    ViewGroup myRootViewGroup = /* root ViewGroup of your activity or fragment */;
    mContext = /* your activity context */;
    
    AlertDialog.Builder builder = new AlertDialog.Builder (mContext, AlertDialog.THEME_HOLO_DARK);
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.mylayout, (ViewGroup) myRootViewGroup);
    builder.setView(layout);
    Dialog dialog = builder.create();
    dialog.show();
    
    .
    .
    .
    dialog.dismiss();
    

    Creating a custom dialog in Android 对此也有很好的回答。

    您可能还认为您要查找的布局基本上是标准的 AlertDialog 布局(没有按钮),您只需执行 builder.setIcon() 和 builder.setTitle()。

    对于您的布局,更改 LinearLayout 方向="horizo​​ntal",完全删除 FrameLayout,设置 ImageView layout_width="wrap_content"。这个:

    <LinearLayout 
    android:id="@id/mylayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    
     <ImageView 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:src=""/>
     <TextView 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="@strings/text"
    />
    
    </LinearLayout>
    

    您可能还想调整图像/文本视图上的填充以获得准确的外观。

    【讨论】:

    • 实际上我希望它像覆盖到另一个活动。如图所示的自定义对话框或平滑。
    • 已编辑答案,我明白你现在的要求了。你需要知道如何做一个自定义对话框,然后你的布局也需要调整
    猜你喜欢
    • 2015-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 1970-01-01
    • 2010-12-18
    • 2014-05-04
    相关资源
    最近更新 更多