[英]How to adjust height's of ImageView in RelativeLayout in android
I've created an view to display errors that contains: 我创建了一个视图来显示包含以下内容的错误:
The description text must be fully displayed: it is displayed on 3 lines. 说明文字必须完整显示:以3行显示。 The "Retry" button has a fixed height and must be visible too.
“重试” 按钮具有固定的高度,也必须可见。 The image must be resized according to the available space.
必须根据可用空间调整图像大小。
For now, the text is not fully displayed: only 2 lines are visible. 目前,该文本尚未完全显示:仅可见两行。 It seems that the image's size is not enough reduced...
图像的大小似乎还不够缩小...
This view is based on a RelativeLayout
, and looks like this: 该视图基于
RelativeLayout
,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@color/color_white">
<ImageView
android:id="@+id/ErrorImageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_marginTop="@dimen/cards_error_image_margin_top"
android:layout_centerHorizontal="true"/>
<TextView
android:id="@+id/ErrorTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/ErrorImageView"
android:layout_marginHorizontal="@dimen/cards_error_text_margin_horizontal"
android:layout_marginTop="@dimen/cards_error_text_margin_top"
style="@style/CustomFont30Marine"
android:gravity="center_horizontal"/>
<Button
android:id="@+id/RetryButton"
android:layout_width="@dimen/cards_error_retry_button_width"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="@dimen/cards_error_retry_button_margin_bottom"
style="@style/WhiteCustomButton"/>
</RelativeLayout>
Is there a way to achieve this through the designer? 有没有办法通过设计师实现这一目标? Or do I need to resize the image programmatically?
还是需要以编程方式调整图像大小?
The expected result looks like this: 预期结果如下所示:
The actual result looks like this: 实际结果如下所示:
Have tried to replicate the design as per your requirements . 尝试根据您的要求复制设计。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
>
<ImageView
android:id="@+id/ErrorImageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:layout_above="@id/ErrorTextView"
android:background="@mipmap/ic_launcher"
android:layout_marginTop="10dp"
android:layout_centerHorizontal="true"/>
<TextView
android:id="@+id/ErrorTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:lines="3"
android:layout_centerHorizontal="true"
android:layout_above="@id/RetryButton"
android:layout_marginHorizontal="10dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"/>
<Button
android:id="@+id/RetryButton"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"
/>
</RelativeLayout>
Hope this helps. 希望这可以帮助。
try 尝试
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@color/color_white"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/ErrorImageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="@dimen/cards_error_image_margin_top"
android:layout_weight="1"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/ErrorTextView"
style="@style/CustomFont30Marine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/cards_error_text_margin_top"
android:gravity="center_horizontal" />
<Button
android:id="@+id/RetryButton"
style="@style/WhiteCustomButton"
android:layout_width="@dimen/cards_error_retry_button_width"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/cards_error_retry_button_margin_bottom" />
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.