创建组框布局,尝试覆盖外框标题

问题描述

public static void testApacheCommons() throws ExecuteException,IOException {

        ByteBuffer byteBuffer = ByteBuffer.allocate(30);

        String readCommand = "sudo dd bs=1 count=30 if=" + "/dev/sdb1" + " skip=50k";
        CommandLine cmdLineForRead = CommandLine.parse(readCommand);
        DefaultExecutor executorRead = new DefaultExecutor();
        ExecuteStreamHandler executeReadStreamHandler = new PumpStreamHandler(
                new ByteBufferBackedOutputStream(byteBuffer));
        executorRead.setStreamHandler(executeReadStreamHandler);
        executorRead.execute(cmdLineForRead,new DefaultExecuteResultHandler());

        String writeCommand = "sudo dd bs=1 of=" + "/dev/sdb2" + " seek=50k";
        CommandLine cmdLineForWrite = CommandLine.parse(writeCommand);

        DefaultExecutor executorWrite = new DefaultExecutor();
        ExecuteStreamHandler executeWriteStreamHandler = new PumpStreamHandler(System.out,System.err,new ByteBufferBackedInputStream(byteBuffer));
        executorWrite.setStreamHandler(executeWriteStreamHandler);
        executorWrite.execute(cmdLineForWrite,new DefaultExecuteResultHandler());

    }

public class ByteBufferBackedInputStream extends InputStream {

    ByteBuffer buf;

    public ByteBufferBackedInputStream(ByteBuffer buf) {
        this.buf = buf;
    }

    public int read() throws IOException {
        if (!buf.hasRemaining()) {
            return -1;
        }
        return buf.get() & 0xFF;
    }

    public int read(byte[] bytes,int off,int len) throws IOException {
        if (!buf.hasRemaining()) {
            return -1;
        }

        len = Math.min(len,buf.remaining());
        buf.get(bytes,off,len);
        return len;
    }
}



public class ByteBufferBackedOutputStream extends OutputStream {
    ByteBuffer buf;

    public ByteBufferBackedOutputStream(ByteBuffer buf) {
        this.buf = buf;
    }

    public void write(int b) throws IOException {
        buf.put((byte) b);
    }

    public void write(byte[] bytes,int len) throws IOException {
        buf.put(bytes,len);
    }

}

我可以尝试创建一个包含一些详细信息的组框。但是我遇到的问题是标题应该显示在组框的边界线上,如图所示。

enter image description here

我使用了CoordinatorLayout,因为我认为这对于覆盖边界线会更好,并且我可以锚定在顶部的起点和终点。

Android 4.0.1

但是,当我在设备上运行时,边框线总是显示在文本标题上。我尝试使用translationZ和height使它们前进。但这不起作用。

这是我跑步时得到的东西

enter image description here

解决方法

使用此代码,您将得到如下图所示的结果

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:background="#FFFFFF"
    android:layout_height="wrap_content">


    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/clGroupBox"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginStart="16dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        android:background="@drawable/stroke"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/tvStandardDeliver"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="16dp"
            android:text="Standard Delivery FREE"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/tvExpressDelivery"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="16dp"
            android:layout_marginBottom="16dp"
            android:text="Express Deliver"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/tvStandardDeliver" />

    </androidx.constraintlayout.widget.ConstraintLayout>

    <TextView
        android:id="@+id/tvHomeDeliver"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:text="Home Delivery"
        android:background="#ffffff"
        android:padding="10dp"
        app:layout_anchor="@id/clGroupBox"
        app:layout_anchorGravity="top|start" />

    <TextView
        android:id="@+id/tvViewDetails"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="32dp"
        android:gravity="center"
        android:background="#FFFFFF"
        android:padding="10dp"
        android:text="View Details"
        app:drawableEndCompat="@android:drawable/arrow_down_float"
        app:layout_anchor="@id/clGroupBox"
        app:layout_anchorGravity="top|end" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...