[英]How do i remove margin from image to a textView when having?
I got a few images and textViews in a LinearLayout. 我在LinearLayout中得到了一些图像和textViews。 The LinearLayout is having margin top and margin bottom 8sp or so. LinearLayout的边距顶部和底部边距为8sp左右。
Problem is all my images are getting that margin aswell even if i tell them to have margin 0 the same way i told my LinearLayout to have margin 0 问题是,即使我告诉它们所有图像的边距都为0,就像我告诉LinearLayout的边距为0一样
As you see, the margin dissapear when i turn the screan to landscape mode. 如您所见,当我将screan转到横向模式时,边距消失。
What have i done wrong? 我做错了什么?
Everything is done programmatically ie no XML files is used. 一切都以编程方式完成,即不使用XML文件。 Here is how i set margin on my LinearLayout 这是我在LinearLayout上设置边距的方法
LinearLayout contentLayout = new LinearLayout(getActivity());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(0,8,0,8);
contentLayout.setLayoutParams(params);
Solved by using android:adjustViewBounds on the image 通过在图像上使用android:adjustViewBounds解决
尝试将方向设置为垂直
contentLayout.setOrientation(1);
Try this: 尝试这个:
//obtain dp equivalent of pixels
final float scale = getResources().getDisplayMetrics().density;
int margin = (int) (5 * scale + 0.5f);
Apply to your layout params. 应用于布局参数。
//setMargins(left, top, right, bottom)
params.setMargins(margin,margin,margin,margin);
I think you are not setting marginLeft 我认为您没有设置marginLeft
Let me know if that helps! 让我知道是否有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.