【发布时间】:2016-03-02 05:49:00
【问题描述】:
无法解决 TableLayout 内的 ImageView 问题。
我将layout_width 和layout_height 都设置为wrap_content,
但是左右两侧出现了一些不需要的区域。
(图片实际上是方形的)
探索了类似的问题
这里
Why do I need to wrap an ImageView into a FrameLayout?
这里
LinearLayout not wrapping content
和其他人
试过
- 设置
adjustViewBounds="true", - 在 dp 中设置固定宽度和高度,
- 玩过
scalTypes, - 包裹在
FrameLayout中,
但对这个问题没有任何帮助。
为什么会出现,如何摆脱它并只包装图像?
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:background="@android:drawable/dialog_holo_light_frame"
android:padding="20dp" >
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tv_deal_number_description"
style="@style/ListHeadingTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/deal_number"
/>
<TextView
android:id="@+id/tv_deal_number"
style="@style/ListHeadingTextStyle"
android:textColor="@color/accent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="1" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View
android:id="@+id/div_under_deal_number"
style="@style/Divider"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/descriptions_vertical_margin"
android:gravity="center" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/ic_margin_right"
android:layout_marginRight="@dimen/ic_margin_right"
android:contentDescription="@null"
android:gravity="start"
android:src="@drawable/ic_person_grey600_24dp"
android:adjustViewBounds="true"
/>
<TextView
android:id="@+id/tv_client_name_description"
style="@style/DescriptionTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/description_value_horizontal_margin"
android:layout_marginRight="@dimen/description_value_horizontal_margin"
android:text="@string/client_name_col" />
<TextView
android:id="@+id/tv_client_name"
style="@style/ListValuesTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:maxLines="2" />
</TableRow>
...
【问题讨论】:
标签: android imageview tablelayout