Android-布局不统一
我在android应用程序中有一个水平的图像列表。但问题是有些图像似乎没有遵循我在xml中定义的布局。像这样: 我的布局如下所示: mainlayout.xmlAndroid-布局不统一,android,android-layout,android-imageview,Android,Android Layout,Android Imageview,我在android应用程序中有一个水平的图像列表。但问题是有些图像似乎没有遵循我在xml中定义的布局。像这样: 我的布局如下所示: mainlayout.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back_shop_list"
android:orientation="horizontal">
<com.devsmart.android.ui.HorizontalListView
android:id="@+id/shop_hlist_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:scrollX="1dp"
android:scrollY="1dp"
android:overScrollMode="always" >
</com.devsmart.android.ui.HorizontalListView>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:translationY="200dp" >
<FrameLayout
android:id="@+id/framelayout"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<ImageView
android:id="@+id/img"
android:clickable="true"
android:adjustViewBounds="true"
android:layout_width="360dp"
android:layout_height="360dp" />
<ProgressBar
android:id="@+id/img_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:translationY="150dp"
android:translationX="140dp" />
</FrameLayout>
<TextView
android:id="@+id/labelText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:translationX="10dp"
android:textColor="#dc6800"
android:textSize="16sp"
android:textStyle="bold" />
<!-- Description label -->
<TextView
android:id="@+id/desc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:translationX="10dp"
android:textColor="#acacac"
android:paddingBottom="2dip">
</TextView>
</LinearLayout>
然后是我的listlayout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back_shop_list"
android:orientation="horizontal">
<com.devsmart.android.ui.HorizontalListView
android:id="@+id/shop_hlist_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:scrollX="1dp"
android:scrollY="1dp"
android:overScrollMode="always" >
</com.devsmart.android.ui.HorizontalListView>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:translationY="200dp" >
<FrameLayout
android:id="@+id/framelayout"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<ImageView
android:id="@+id/img"
android:clickable="true"
android:adjustViewBounds="true"
android:layout_width="360dp"
android:layout_height="360dp" />
<ProgressBar
android:id="@+id/img_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true"
android:translationY="150dp"
android:translationX="140dp" />
</FrameLayout>
<TextView
android:id="@+id/labelText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:translationX="10dp"
android:textColor="#dc6800"
android:textSize="16sp"
android:textStyle="bold" />
<!-- Description label -->
<TextView
android:id="@+id/desc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:translationX="10dp"
android:textColor="#acacac"
android:paddingBottom="2dip">
</TextView>
</LinearLayout>
我的猜测是,我的图像的大小小于我的ImageView布局的宽度和高度。或者我真的不知道是什么导致了这个问题。
但是任何帮助都可以。谢谢
编辑:我真正想要的是,如果图像像图4和图5一样,它不应该有那些空格。我尝试从ImageLoader中获取图像的大小,然后在加载图像时在其中设置布局参数height和width。但情况看起来更糟。
如果图像与图4和图5相似,是否有其他方法可以动态调整ImageView 如果确实要使图像占据所需的空间
尝试将此图像视图属性添加到ImageView
您可以尝试其他我通常使用的fitXY
,从预定义列表中,您将在XML布局中找到它们
android:scaleType="fitXY"
为了使这一财产发挥作用,我们还需要
android:adjustViewBounds="true"
您已经添加到您的案例中
如果你真的想避免空白,让图像占据它想要的空间
在我的布局中,我使用两个图像视图来显示演示
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_numbers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="@+id/tv_numbers"
android:layout_below="@+id/tv_numbers"
android:layout_marginTop="5dip"
android:layout_marginRight="10dip"
android:orientation="vertical">
<ImageView
android:id="@+id/textView1"
android:layout_width="200dip"
android:layout_height="200dip"
android:src="@drawable/desert"/>
<ImageView
android:id="@+id/textView2"
android:layout_width="200dip"
android:layout_height="200dip"
android:background="@drawable/desert"/>
</LinearLayout>
如果确实要使图像占据所需的空间
尝试将此图像视图属性添加到ImageView
您可以尝试其他我通常使用的fitXY
,从预定义列表中,您将在XML布局中找到它们
android:scaleType="fitXY"
为了使这一财产发挥作用,我们还需要
android:adjustViewBounds="true"
您已经添加到您的案例中
如果你真的想避免空白,让图像占据它想要的空间
在我的布局中,我使用两个图像视图来显示演示
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_numbers"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignLeft="@+id/tv_numbers"
android:layout_below="@+id/tv_numbers"
android:layout_marginTop="5dip"
android:layout_marginRight="10dip"
android:orientation="vertical">
<ImageView
android:id="@+id/textView1"
android:layout_width="200dip"
android:layout_height="200dip"
android:src="@drawable/desert"/>
<ImageView
android:id="@+id/textView2"
android:layout_width="200dip"
android:layout_height="200dip"
android:background="@drawable/desert"/>
</LinearLayout>
将android:scaleType添加到ImageView。尝试不同的选项-FIT_CENTER可能会满足您的需要。我猜您希望添加图像,并将其调整为屏幕的宽度和高度?是的,我添加图像并将其调整为视图的宽度和高度..而不是screen@Simon好的,我会试试那些东西。我的图像看起来很糟糕。我可以只获取图像的大小,然后在活动中调整imageView吗?将android:scaleType添加到imageView中。尝试不同的选项-FIT_CENTER可能会满足您的需要。我猜您希望添加图像,并将其调整为屏幕的宽度和高度?是的,我添加图像并将其调整为视图的宽度和高度..而不是screen@Simon好的,我会试试那些东西。我的图像看起来很糟糕。我可以只获取图像的大小,然后在活动中调整我的imageView吗?我的图像看起来很糟糕。我的意思是,如果图像较小,它不应该有额外的空间。所以,我无法根据从url加载的图像的大小调整版面宽度和高度?如果这些属性对您没有帮助,请尝试按照我上面的更新。至少我不知道是否有其他方法可以修复它。。因为我们在XML布局中给出了固定的布局宽度和布局高度,所以它的行为实际上应该是这样的。将imageview的宽度设置为“wrap_content”。当它试图在提供的图像视图维度中保持图像的接受率时,它会提供空白。。所以你不能肯定地说,小尺寸的图像正在这样做。。。这实际上是图像的接受率。。。。如果你想让图像占据实际图像的大小,请使用“包装内容”(实际上我认为你不想这样做,因为通过URL发送的大图像会破坏整个布局)。。。或者让它用“比例类型”来填充空间(我至少会选择后者),我的图像看起来很糟糕。我的意思是,如果图像较小,它不应该有额外的空间。所以,我无法根据从url加载的图像的大小调整版面宽度和高度?如果这些属性对您没有帮助,请尝试按照我上面的更新。至少我不知道是否有其他方法可以修复它。。因为我们在XML布局中给出了固定的布局宽度和布局高度,所以它的行为实际上应该是这样的。将imageview的宽度设置为“wrap_content”。当它试图在提供的图像视图维度中保持图像的接受率时,它会提供空白。。所以你不能肯定地说,小尺寸的图像正在这样做。。。这实际上是图像的接受率。。。。如果你想让图像占据实际图像的大小,请使用“包装内容”(实际上我认为你不想这样做,因为通过URL发送的大图像会破坏整个布局)。。。或者让它使用“比例类型”填充空间(我至少会选择后者)