我试图在名为 divider1、divider2 和 divider3 的 ImageView 中心获取图像。但我得到的只是:-
正如您在分数 和评论 之间看到的那样,图像稍微向上移动了一点。图像是一个 5x5 像素的“点”。
我的 XML 文件:-
<?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:orientation="vertical"
android:background="#d3d3d3"
android:padding="10dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/rounded">
<TextView
android:id="@+id/list_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#ffffff"
android:padding="2dp"/>
<LinearLayout
android:id="@+id/ll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="2dp">
<TextView
android:id="@+id/list_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:padding="2dp" />
<ImageView
android:id="@+id/divider1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/divider"
android:scaleType="centerInside"
android:padding="2dp"/>
<TextView
android:id="@+id/list_domain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:padding="2dp" />
<ImageView
android:id="@+id/divider2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/divider"
android:scaleType="centerInside"
android:padding="2dp"/>
<TextView
android:id="@+id/list_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:padding="2dp"/>
</LinearLayout>
<ImageView
android:id="@+id/list_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<LinearLayout
android:id="@+id/ll2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="2dp" >
<TextView
android:id="@+id/list_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:padding="2dp" />
<ImageView
android:id="@+id/divider3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/divider"
android:scaleType="centerInside"
android:padding="2dp"/>
<TextView
android:id="@+id/list_comments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff"
android:padding="2dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
有什么问题吗?
最佳答案
ImageView 是否环绕取决于它的内容
android:layout_width="wrap_content"
设置 ImageView 高度以匹配容器。然后将图像居中:
<ImageView
android:id="@+id/divider3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="center"
android:src="@drawable/divider"
android:padding="2dp"/>
在您的 imageView 中设置它们。
关于android - 嵌套 LinearLayout 内 ImageView 中心的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27381007/