Android ImageView在线性布局下变得非常小
在我的一个屏幕上,我希望实现这种布局 最重要的是正确缩放图像。我给出的这些图像具有足够的分辨率,可以在另一个片段布局上很好地工作。 我的layout.xml如下所示Android ImageView在线性布局下变得非常小,android,android-layout,imageview,android-linearlayout,Android,Android Layout,Imageview,Android Linearlayout,在我的一个屏幕上,我希望实现这种布局 最重要的是正确缩放图像。我给出的这些图像具有足够的分辨率,可以在另一个片段布局上很好地工作。 我的layout.xml如下所示 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" a
<?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:background="@drawable/stadiumbg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/listview_item"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="left"
android:orientation="vertical" >
<ImageView
android:id="@+id/image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:adjustViewBounds="true"
android:padding="5dp"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/title1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="70%"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="80%"
android:textAppearance="?android:attr/textAppearanceLarge" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<ImageView
android:id="@+id/image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:adjustViewBounds="true"
android:padding="5dp"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/title2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/listview_item"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vote" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Down Vote" />
</LinearLayout>
</LinearLayout>
其他一切都很好。可绘制的listview_项目是提供圆角的,并在listview中使用上述图像进行测试。很好。
但是在这个布局中,两幅图像都被超级缩小了。是这样的
无缘无故地浪费所有的空间。
我所尝试的:
adjustViewBounds设置为false
鳞状体
想得到我想要的吗?更改ImageView的宽度和高度。而不是:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
使用:
更改数字以满足您的需要。但如果是在低分辨率手机中,这将是一个问题,不是吗?不,不会。dp代表与密度无关的像素。我试过了。我在nexus上设置了200dp。图像变得很大,但文本在图像上重叠(text1和text2)。。所以,我减少它,使它正确,比如说,100dp。假设它现在在我的nexus上运行良好,现在在一个较小的sceen上,它可能仍然重叠na?我一直在使用它,我在Note 3和一个2.8英寸的手机上试用过,它工作正常。好的。谢谢你的回答
android:layout_width="200dp"
android:layout_height="200dp"