我想增加绿线的高度,增加aa长度的大小(假设aa是多线7线左右,那么绿线应该自动增加), 我已经尝试过我的努力但失败了,现在我已经没有更多的想法来实现上面提到的,以下是我的上述布局的xml,
//My root layout, which/who contain all the two child layouts(relative and linear layout)
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
//Layout for image and line, here i want to increase the height of "profile_view_line(green line)" with increase in size of text "profile_tv_descriptionName"
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/profile_layout_relDescription">
//This is the imageview,whose background is tranparent, so if i remove "layout below " property from "profile_view_line", then "profile_view_line"
//appear behind imageview(profile_img_description),which must/should not happen, but here i fail as well (as i don't want to appear this behind imageview)
<ImageView android:id="@+id/profile_img_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/description_icon"
android:layout_alignParentLeft="true"/>
//This is the line to be expanded with increase in size of "profile_tv_descriptionName" but with minimum size of 30dp as height
//and must grow with the "profile_tv_descriptionName" if (profile_tv_descriptionName) is multi-line
//i can't set property depending on "profile_tv_descriptionName"
as it is in another viewgroup(relativeayout), due to which i can't set property on this one
<View android:layout_below="@id/profile_img_description"
android:layout_width="@dimen/1dp"
android:id="@+id/profile_view_line"
android:layout_height="@dimen/30dp"
android:background="@color/colorGreen"
android:layout_centerHorizontal="true" />
</RelativeLayout>
//Layout for description title and description text "aa" which exapnds as expected, here the dependincy is based on above maintained relative layout "profile_layout_relDescription"
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_toRightOf="@id/profile_layout_relDescription"
android:layout_alignBottom="@id/profile_layout_relDescription">
//This is the title, useless in this case but need for appearance
<TextView
android:id="@+id/profile_tv_description"
android:text="@string/profile_description"
android:textSize="@dimen/8dp"
android:gravity="left"/>
//this is the dependency factor which can increase and according to which "profile_view_line" green line must expand but i can't do
//that because it is in another viewgroup(linearlayout), due to which i can't set property on this one
<TextView
android:layout_height="wrap_content"
android:id="@+id/profile_tv_descriptionName"
android:text="Vikram"
android:textSize="@dimen/13dp"
android:gravity="left"/>
</LinearLayout>
</RelativeLayout>
答案 0 :(得分:2)
尝试这样的布局:
<LinearLayout, horizontal>
<LinearLayout, vertical, width wrap_content, height match_parent, gravity center_horizontal>
<ImageView set width, set height>
<View, greeen line, height 0, weight 1>
</LinearLayout>
<LinearLayout, vertical, width 0, height wrap_content, weight 1>
<TextView title, wrap_content>
<TextView description, wrap_content>
</LinearLayout>
</LinearLayout>
<强>解释强>
你需要四个方块:
AB
CD
其中A是图像,B是标题,C是行,D是文本。
B和D需要彼此垂直对齐,并且在A和C旁边,这样我就知道这些对中的每一对应该是垂直线性布局,然后这两个应该在水平对齐一个排队。
A和C一起具有A所具有的宽度,但另外两个需要占用剩余空间。这意味着宽度为0,重量为1。
现在我们有:
A B----------------------
C D----------------------
现在我们需要处理身高。 A具有固定的高度。 B和D具有固定的高度,由其中的文本定义。这使得C具有可变高度,占据了剩余的空间。因此我们说AC的高度与父级匹配,然后由BD的高度定义。然后C的高度为0,重量为1,使其填满所有剩余高度。这给了我们:
A B----------------------
C D----------------------
- -----------------------