Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用css的相同技术;“负保证金”;在布局中?_Android_Android Layout_Layout_Android Constraintlayout - Fatal编程技术网

Android 如何使用css的相同技术;“负保证金”;在布局中?

Android 如何使用css的相同技术;“负保证金”;在布局中?,android,android-layout,layout,android-constraintlayout,Android,Android Layout,Layout,Android Constraintlayout,我想创建你在图片中看到的这种布局,我想在CSS中使用负边距,但没有结果。请帮我实现它。 这是盒子: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle">

我想创建你在图片中看到的这种布局,我想在CSS中使用负边距,但没有结果。请帮我实现它。


这是盒子:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#2d3669"></solid>
            <corners android:radius="50dp"></corners>
            <gradient android:angle="90"
                android:startColor="#392800"
                android:endColor="#faae03"/>
        </shape>
    </item>
</selector>

我知道在
ConstraintLayout
中如何让项目彼此靠近,但我不知道如何将日志放在
TextView
上,使其中一半保持在外部!我在谷歌上找不到一个导致此类示例的关键字。

给你:

<?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=".MainActivity"
    tools:layout_editor_absoluteY="81dp">

<TextView
    android:id="@+id/txt_home_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/box"
    android:elegantTextHeight="true"
    android:padding="30dp"
    android:text="Welcome!"
    android:textColor="#ffffff"
    android:textSize="28sp"
    tools:layout_editor_absoluteX="129dp"
    tools:layout_editor_absoluteY="0dp" />

<android.support.v4.widget.Space
    android:id="@+id/space"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginBottom="32dp"
    app:layout_constraintBottom_toBottomOf="@+id/txt_home_title"
    app:layout_constraintLeft_toLeftOf="@id/txt_home_title"
    app:layout_constraintRight_toRightOf="@id/txt_home_title" />

<ImageView
    android:id="@+id/home_logo"
    android:layout_width="98dp"
    android:layout_height="84dp"
    android:scaleType="fitCenter"
    android:src="@mipmap/ic_launcher"
    app:layout_constraintHorizontal_bias="0.687"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/space" />

</android.support.constraint.ConstraintLayout>

说明:

我们不能在
ConstraintLayout
中使用负边距,因为它是这样的,所以我们需要使用一种变通方法。在
ImageView
TextView
之间添加一个空视图,即
Space
,并将
android:layout_marginBottom=“32dp”
设置为
Space
视图,即可完成操作

我遵循了Commonware的答案。

给你:

<?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=".MainActivity"
    tools:layout_editor_absoluteY="81dp">

<TextView
    android:id="@+id/txt_home_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/box"
    android:elegantTextHeight="true"
    android:padding="30dp"
    android:text="Welcome!"
    android:textColor="#ffffff"
    android:textSize="28sp"
    tools:layout_editor_absoluteX="129dp"
    tools:layout_editor_absoluteY="0dp" />

<android.support.v4.widget.Space
    android:id="@+id/space"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginBottom="32dp"
    app:layout_constraintBottom_toBottomOf="@+id/txt_home_title"
    app:layout_constraintLeft_toLeftOf="@id/txt_home_title"
    app:layout_constraintRight_toRightOf="@id/txt_home_title" />

<ImageView
    android:id="@+id/home_logo"
    android:layout_width="98dp"
    android:layout_height="84dp"
    android:scaleType="fitCenter"
    android:src="@mipmap/ic_launcher"
    app:layout_constraintHorizontal_bias="0.687"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/space" />

</android.support.constraint.ConstraintLayout>

说明:

我们不能在
ConstraintLayout
中使用负边距,因为它是这样的,所以我们需要使用一种变通方法。在
ImageView
TextView
之间添加一个空视图,即
Space
,并将
android:layout_marginBottom=“32dp”
设置为
Space
视图,即可完成操作


我遵循了Commonware的答案。

至少有两种不同的方法可以实现这一点

1。主播

如果希望徽标的中心正好位于TextView的底部边缘,请使用坐标布局作为徽标和TextView的直接父视图,并在徽标上使用
app:layout\u锚定
app:layout\u锚定
XML属性。例如,
app:layout_anchor
的值将是TextView的ID,
app:layout_anchorGravity
的值将是“bottom | end”

请注意,您应该能够通过将徽标封装在父布局中,将父视图锚定到TextView,然后在徽标上设置边距以在其透明父视图中移动来实现所需的任何定位

2。负利润率(yep)

Android实际上支持负利润率,尽管可能不支持约束性调整。不过,它肯定与相对年轻人一起工作!考虑到您希望ImageView与TextView重叠,它将如下所示:

<RelativeLayout
    ...

    <TextView
        android:id="@+id/myTextView"
        ... />

    <ImageView
        android:layout_below="@+id/myTextView"
        android:layout_marginTop="-30dp"
        ... />
 </RelativeLayout>

至少有两种不同的方法可以实现这一点

1。主播

如果希望徽标的中心正好位于TextView的底部边缘,请使用坐标布局作为徽标和TextView的直接父视图,并在徽标上使用
app:layout\u锚定
app:layout\u锚定
XML属性。例如,
app:layout_anchor
的值将是TextView的ID,
app:layout_anchorGravity
的值将是“bottom | end”

请注意,您应该能够通过将徽标封装在父布局中,将父视图锚定到TextView,然后在徽标上设置边距以在其透明父视图中移动来实现所需的任何定位

2。负利润率(yep)

Android实际上支持负利润率,尽管可能不支持约束性调整。不过,它肯定与相对年轻人一起工作!考虑到您希望ImageView与TextView重叠,它将如下所示:

<RelativeLayout
    ...

    <TextView
        android:id="@+id/myTextView"
        ... />

    <ImageView
        android:layout_below="@+id/myTextView"
        android:layout_marginTop="-30dp"
        ... />
 </RelativeLayout>

查看一些关于ConstraintLayout;)的教程@AdrianDain如果您想使用坐标布局,您可以给出
@drawable/box
。是布局元素让你可以把元素放在彼此的上面。我也找不到教程。。。谷歌…看一些关于ConstraintLayout;)的教程@AdrianDain如果您想使用坐标布局,您可以给出
@drawable/box
。是布局元素让你可以把元素放在彼此的上面。我也找不到教程。。。谷歌。。。