Java ImageView留下不需要的上/下边距/填充
我正在设计一个Android XML布局,其中包含一些代表复选标记和红色X的图像的ImageView。我遇到了一些问题,这些图像在屏幕上显示时包含额外的边距/填充 请注意,似乎没有右边距或左边距/填充,但有大量的顶部/底部填充 这些图像是PNG格式,遵循中介绍的创建小/上下文图标的指导原则 我想通过使边距/填充与其水平边距/填充的效果相匹配来纠正这个问题 以下是布局的XML:Java ImageView留下不需要的上/下边距/填充,java,android,xml,layout,imageview,Java,Android,Xml,Layout,Imageview,我正在设计一个Android XML布局,其中包含一些代表复选标记和红色X的图像的ImageView。我遇到了一些问题,这些图像在屏幕上显示时包含额外的边距/填充 请注意,似乎没有右边距或左边距/填充,但有大量的顶部/底部填充 这些图像是PNG格式,遵循中介绍的创建小/上下文图标的指导原则 我想通过使边距/填充与其水平边距/填充的效果相匹配来纠正这个问题 以下是布局的XML: <!-- Event Reoccuring --> <LinearLayou
<!-- Event Reoccuring -->
<LinearLayout
android:id="@+id/event_reoccur_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
>
<TextView
android:id="@+id/kid_event_reoccur_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_gravity="center_vertical"
android:text="@string/event_reoccur"
/>
<ImageView
android:id="@+id/kid_event_reoccur_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:layout_gravity="center_vertical"
android:contentDescription="@string/indicator"
/>
<TextView
android:id="@+id/kid_event_reoccur"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:layout_gravity="center_vertical"
android:paddingLeft="4dp"
android:text="@string/not_applicable"
/>
</LinearLayout>
<!-- Age Required -->
<LinearLayout
android:id="@+id/event_age_req_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp"
>
<TextView
android:id="@+id/kid_event_age_req_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_gravity="center_vertical"
android:text="@string/event_age_req"
/>
<ImageView
android:id="@+id/kid_event_age_req_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:gravity="center_vertical"
android:contentDescription="@string/indicator"
/>
<TextView
android:id="@+id/kid_event_age_req"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:layout_gravity="center_vertical"
android:paddingLeft="4dp"
android:text="@string/not_applicable"
/>
</LinearLayout>
刚刚通过另一个问题找到了解决方案:
XML对象上的android:adjustViewBounds=“true”
解决了这个问题。刚刚通过另一个问题找到了解决方案:
XML对象上的android:adjustViewBounds=“true”
解决了这个问题。使用RelativeLayout而不是LinearLayout。此外,除非有必要,否则尽量避免使用权重等属性。使用RelativeLayout而不是LinearLayout。此外,除非必要,否则尽量避免使用权重等属性。请详细说明“除非必要,否则尽量避免使用权重等属性”?重量不是不推荐的…”“除非必要,否则尽量避免使用重量等属性”您能详细说明吗?重量不是不推荐的。。。
@TargetApi(16)
private void setupEventReoccurence(View v) {
// Get Reference
mReoccurence = (TextView) v.findViewById(R.id.kid_event_reoccur);
mReoccurence.setText(boolToString(mEvent.isReoccuring()));
// Checkmark/X indicator
mReoccurIndicator = (ImageView) v.findViewById(R.id.kid_event_reoccur_indicator);
mReoccurIndicator.setImageResource(R.drawable.greencheck_small_context_icon);
mReoccurIndicator.setScaleType(ScaleType.CENTER_INSIDE);
mReoccurIndicator.setCropToPadding(true);
//mReoccurIndicator.setMaxHeight((int) mReoccurence.getTextSize());
//mReoccurIndicator.setMinimumHeight((int) mReoccurence.getTextSize());
Log.d(TAG, "getTextSize() as float: " + mReoccurence.getTextSize());
Log.d(TAG, "getTextSize() as int: " + (int) mReoccurence.getTextSize());
}
@TargetApi(16)
private void setupEventAgeReq(View v) {
// Get Reference
mAgeReq = (TextView) v.findViewById(R.id.kid_event_age_req);
mAgeReq.setText(boolToString(mEvent.isAgeReq()));
// Checkmark/X indicator
mAgeReqIndicator = (ImageView) v.findViewById(R.id.kid_event_age_req_indicator);
mAgeReqIndicator.setImageResource(R.drawable.greencheck_small_context_icon);
mAgeReqIndicator.setScaleType(ScaleType.CENTER_INSIDE);
mAgeReqIndicator.setCropToPadding(true);
//mAgeReqIndicator.setMaxHeight((int) mReoccurence.getTextSize());
//mAgeReqIndicator.setMinimumHeight((int) mReoccurence.getTextSize());
Log.d(TAG, "getTextSize() as float: " + mReoccurence.getTextSize());
Log.d(TAG, "getTextSize() as int: " + (int) mReoccurence.getTextSize());
}