随着文本大小的增加(多行)增加布局的长度
increase the length of layout with increase in size of text(multi-line)
我想增加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>
试试这样的布局:
<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>
解释:
一个正方形需要 4 个东西:
AB
CD
其中 A 是图像,B 是标题,C 是行,D 是文本。
B 和 D 需要彼此垂直对齐,并紧挨着 A 和 C,所以对我来说,每一对都应该采用垂直线性布局,然后这两对应该对齐一个水平的把它们排成一行。
A和C加起来有A的宽度,但是另外两个需要占剩下的space。这意味着宽度为 0,重量为 1。
现在我们有:
A B----------------------
C D----------------------
现在我们需要处理高度。 A 有一个固定的高度。 B 和 D 具有固定的高度,由其中的文本定义。这使得 C 的高度可变,占据了 space 的其余部分。所以我们说 AC 的高度匹配 parent,然后由 BD 的高度定义。然后 C 的高度为 0,重量为 1,使其填满所有剩余高度。这给了我们:
A B----------------------
C D----------------------
- -----------------------
我想增加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>
试试这样的布局:
<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>
解释:
一个正方形需要 4 个东西:
AB
CD
其中 A 是图像,B 是标题,C 是行,D 是文本。
B 和 D 需要彼此垂直对齐,并紧挨着 A 和 C,所以对我来说,每一对都应该采用垂直线性布局,然后这两对应该对齐一个水平的把它们排成一行。
A和C加起来有A的宽度,但是另外两个需要占剩下的space。这意味着宽度为 0,重量为 1。
现在我们有:
A B----------------------
C D----------------------
现在我们需要处理高度。 A 有一个固定的高度。 B 和 D 具有固定的高度,由其中的文本定义。这使得 C 的高度可变,占据了 space 的其余部分。所以我们说 AC 的高度匹配 parent,然后由 BD 的高度定义。然后 C 的高度为 0,重量为 1,使其填满所有剩余高度。这给了我们:
A B----------------------
C D----------------------
- -----------------------