代码之家  ›  专栏  ›  技术社区  ›  Xavier L.

Android布局编辑器:如何添加一个简单的视图?

  •  0
  • Xavier L.  · 技术社区  · 8 年前

    有没有办法将一个空白视图从Android布局编辑器中的调色板拖到我正在创建的视图上(不必输入原始XML)?

    以下是我在“公共”部分看到的: Common Palette

    Palette search for view

    我遗漏了什么吗?

    我在“容器”部分下看到了一个“<view>”,但它只是弹出一个弹出窗口,其中包含的内容与调色板中已经存在的内容相同。

    我是Android开发人员的新手,来自iOS,我可以把一个UIView直接拖到故事板上。在Android中,这种行为相当于什么?

    有什么方法可以让我将自己的自定义内容添加到布局编辑器调色板中吗?

    正在键入 <View ... /> 在原始XML中,实现这一点的唯一方法是什么?

    3 回复  |  直到 8 年前
        1
  •  0
  •   tomasznajda    8 年前

    你可以用 android:alpha="0.5" 设置50%不透明度。

    <View
            android:id="@+id/overlayOrSomethingElse"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="top"
            android:alpha="0.5"
            android:background="@android:color/black" />
    
        2
  •  0
  •   mrvinent    8 年前

    有一个 View 在调色板上,你可以这样做。

    <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".Main2Activity">
    
        <View
            android:id="@+id/view"
            android:layout_width="wrap_content"
            android:layout_height="243dp"
            android:background="#0000ff"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="349dp" />
    
        <View
            android:id="@+id/view3"
            android:layout_width="wrap_content"
            android:layout_height="4dp"
            android:background="#ffffff"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="469dp" />
    
    </android.support.constraint.ConstraintLayout>
    
        3
  •  0
  •   Xavier L.    8 年前

    我的眼睛发疯了。

    在“视图”中拖动(绿色圆圈)

    found it

    有谁能解释为什么在“Widgets”下面?

    推荐文章