Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.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 近乎环绕的TextView是在LinearLayout中剪裁ImageView_Android_Layout - Fatal编程技术网

Android 近乎环绕的TextView是在LinearLayout中剪裁ImageView

Android 近乎环绕的TextView是在LinearLayout中剪裁ImageView,android,layout,Android,Layout,我有一个水平线性布局集来包装内容。内部是一个垂直线性布局,包含一个文本视图,允许多行内容和一个ImageButton内容。有几个组件有边距和填充,因此可以很好地隔开 当文本视图中的文本较短时,一切正常。当文本换行到多行时,仍然可以。当文本几乎长到可以换行时,ImageButton会被水平剪裁,其左右两侧会被剪掉。如果我把边距拉出来填充,效果会很好,但当然看起来不太好 我的猜测是,布局系统在计算文本宽度时没有考虑一些边距和填充。然后它开始布局,总空间比TextView的第一步要小,因此它在布局中剪

我有一个水平线性布局集来包装内容。内部是一个垂直线性布局,包含一个文本视图,允许多行内容和一个ImageButton内容。有几个组件有边距和填充,因此可以很好地隔开

当文本视图中的文本较短时,一切正常。当文本换行到多行时,仍然可以。当文本几乎长到可以换行时,ImageButton会被水平剪裁,其左右两侧会被剪掉。如果我把边距拉出来填充,效果会很好,但当然看起来不太好

我的猜测是,布局系统在计算文本宽度时没有考虑一些边距和填充。然后它开始布局,总空间比TextView的第一步要小,因此它在布局中剪切第二项并尊重计算出的TextView宽度。但这只是一个猜测

除了写我自己的布局,还有什么想法吗

编辑

下面是hierarchy viewer的屏幕截图,显示了ImageButton被剪裁的位置,并突出显示了相关的XML。ImageButton的边界与我看到的一致:27dp宽,而圆形图像本身实际上是36dp宽,ImageButton在每侧指定了4dp填充

再一次,我必须小心地选择文本:只要短一点,按钮就可以了;再长一点,它就会包起来,纽扣又好了

编辑

下面是我的XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/messageBubble"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:minHeight="@dimen/message_bubble_min_height"
        android:layout_alignTop="@id/avatar"
        android:layout_alignLeft="@id/avatar"
        android:layout_marginTop="@dimen/message_bubble_margin_top"
        android:layout_marginLeft="@dimen/message_bubble_inset"
        android:layout_marginRight="@dimen/message_inbound_padding_inside"
        android:paddingLeft="@dimen/message_bubble_padding_outside"
        android:paddingRight="@dimen/message_bubble_padding_inside"
        android:paddingTop="@dimen/message_bubble_padding_v"
        android:paddingBottom="@dimen/message_bubble_padding_v"
        android:orientation="horizontal">

    <LinearLayout
            android:id="@+id/contentContainer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:orientation="vertical">
        <TextView
                android:id="@+id/messageBody"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/message_body_margin_outside"
                android:layout_marginRight="@dimen/message_body_margin_inside"
                android:layout_marginTop="@dimen/message_body_margin_v"
                android:layout_marginBottom="@dimen/message_body_margin_v"
                android:gravity="left"
                android:autoLink="all"
                android:textSize="17dp" />
    </LinearLayout>

    <include layout="@layout/view_message_action_btn" />

</LinearLayout>
以及包含的视图、消息、操作:

<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/actionButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@null"
    android:src="@drawable/action_btn"
    android:paddingLeft="@dimen/message_action_btn_padding_h"
    android:paddingRight="@dimen/message_action_btn_padding_h" />

你用过hierarchyviewer吗?如果是这样的话,布局看起来像是右下角的窗口吗?见上文…我添加了一个来自hierarchy viewer的屏幕截图。我的意思是这部分视图显示为红色框架,如果看起来更好,你可以使用复选框切换到白色背景。我很困惑。在我发布的屏幕截图中,你可以在ImageButton周围看到一个红色框…我可以将鼠标悬停在其他视图上,也可以看到它们周围的框。它旁边的文本视图有一个框架正好围绕着它的文本,而它周围的线性布局只是稍微大一点,正好对着ImageButton。你在说别的吗?好的,把你的布局xml文件也贴出来