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
包含wrap_内容的Android布局_Android_Layout_Listitem - Fatal编程技术网

包含wrap_内容的Android布局

包含wrap_内容的Android布局,android,layout,listitem,Android,Layout,Listitem,我试图创建自定义列表项布局,但遇到问题。请参见下面的示例: 有效运作 问题 问题是当绿色矩形填充所有蓝色框时(宽度设置为wrap\u content),因为绿色正方形消失了。正方形必须在绿色矩形的右边,但是这个矩形的大小可以改变,我不能将绿色正方形固定在蓝色框的右边 红色矩形是固定的,它们不是问题 我使用了一些LinearLayout和RelativeLayout来实现这一点,但它没有按照我的意愿工作。 我也不能使用drawableRight属性,因为在不久的将来,将有两个图标(绿色正方形)

我试图创建自定义列表项布局,但遇到问题。请参见下面的示例:

有效运作

问题

问题是当绿色矩形填充所有蓝色框时(宽度设置为
wrap\u content
),因为绿色正方形消失了。正方形必须在绿色矩形的右边,但是这个矩形的大小可以改变,我不能将绿色正方形固定在蓝色框的右边

红色矩形是固定的,它们不是问题

我使用了一些
LinearLayout
RelativeLayout
来实现这一点,但它没有按照我的意愿工作。 我也不能使用
drawableRight
属性,因为在不久的将来,将有两个图标(绿色正方形)而不是一个

如果有人已经遇到这个问题或有办法解决这个问题

结果是:

[[ListIconView][[Some text here][Icon]]<..空格..>[x][y][z]]

[[ListIconView][[Long text from……][Icon]]<.空格..>[x][y][z]]

[[ListIconView][[一本旧书中的很长的文本…][Icon]][x][y][z]]


x、 y和z是图标

假设红方块和矩形不是问题(父布局可能是
RelativeLayout
),并且您将
TextView
ImageView
作为绿色矩形和绿色正方形,使用

android:layout_weight="1"
对于您的
文本视图
(绿色矩形)


假设红方块和矩形不是问题所在(可能父布局是
RelativeLayout
),并且您将
文本视图
图像视图
作为绿色矩形和绿色正方形,请使用

android:layout_weight="1"
对于您的
文本视图
(绿色矩形)



我在上面所做的是,我根据我想要适合根布局的每个项目的百分比分配空间,根布局是线性布局,占总权重的100%。ImageView将占用20%的空间,然后是另一个线性布局,它将占用60%,最后是ImageButton,它也占用20%



我在上面所做的是,我根据我想要适合根布局的每个项目的百分比分配空间,根布局是线性布局,占总权重的100%。ImageView将占用20%的空间,然后是另一个线性布局,将占用60%,最后是ImageButton,也将占用20%

请包含一些代码。请添加相关的布局文件。@Cylon阅读答案了吗?@DamianKozlak是的,它不起作用!我正在考虑创建自己的视图组!请包含一些代码。请添加相关的布局文件。@Cylon你读过答案吗?@DamianKozlak是的,它不工作!我正在考虑创建自己的视图组!
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="100">

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="20" 
        android:text="blablah"/>

    <LinearLayout
        android:layout_weight="60"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:weightSum="100">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="80"
            android:text="test string string string"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="20"
            android:text="String test"/>

    </LinearLayout>

    <ImageButton
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="20"/>

</LinearLayout>