无法解决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"
,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>
...
答案 0 :(得分:0)
虽然你设置尺寸wrap_content,但你也设置了边距。
android:layout_marginEnd="@dimen/ic_margin_right"
android:layout_marginRight="@dimen/ic_margin_right"
尝试删除这些arrributes或将它们设置为0。
答案 1 :(得分:0)
实际上这是由于你的形象造成的。尝试将您的图像裁剪为合适的。您的图像在左侧和左侧保留了额外的空间。右侧甚至图像也是透明的。重试它有帮助。
答案 2 :(得分:0)
由于标题出现了问题 从表格的第一行删除标题后,ImageViews开始没有边距,只是包装内容 (说实话我不知道为什么) 所以我只是将标题放在表格布局之外并实现了预期:
现在代码如下:
<?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_marginTop="8dp"
android:background="@android:drawable/dialog_holo_light_frame"
android:orientation="vertical"
android:padding="20dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:textColor="@color/accent" />
</LinearLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<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:adjustViewBounds="true"
android:contentDescription="@null"
android:gravity="start"
android:src="@drawable/ic_person_grey600_24dp" />
<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>
...