2017-03-07 63 views
0

我搜索了一个我的问题的答案,但是我找不到符合我的情况的答案。所以我的应用程序是一个计算机的在线商店。我做了两个listViews和两个自定义的行..一个用于商店,另一个用于购物篮。他们都展示了该产品的一些功能,而且它的图片在右侧。我的问题是我的图片(他们直接从服务器)无法正确地放在我的ImageViews和ListViews中,我正在寻找解决方案。提前谢谢将ImageView合并到列表中查看

ps:我使用Picasso库来显示图片。 的代码所使用的毕加索行:

Picasso.with(this.getContext()).load(lFoto).into(foto); 

custom_row_shop.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="horizontal" > 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/list_ref" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="Ref Artikel :" 
      android:textColor="#2383c4" 
      android:textSize="11sp" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="Betriebssytem :" 
      android:textSize="9sp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/list_betriebssystem" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="sldjq" 
      android:textSize="9sp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="Prozessor :" 
      android:textSize="9sp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/list_prozessor" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="sldjq" 
      android:textSize="9sp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="Grafikkarte :" 
      android:textSize="9sp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/list_grafikkarte" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="sldjq" 
      android:textSize="9sp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="RAM :" 
      android:textSize="9sp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/list_arbeitsspeicher" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="sldjq" 
      android:textSize="9sp" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="Festplatte :" 
      android:textSize="9sp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/list_festplatte" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="sldjq" 
      android:textSize="9sp" /> 
    </LinearLayout> 
</LinearLayout> 

<ImageView 
    android:id="@+id/list_foto" 
    android:layout_width="90dp" 
    android:layout_height="90dp" 
    android:layout_marginLeft="40dp" 
    android:layout_marginTop="20dp" 
    android:scaleType="centerCrop" 
    android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

custom_row_basket.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="horizontal" > 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:id="@+id/list_warenKorb_ref" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="Ref Artikel :" 
      android:textColor="#2383c4" 
      android:textSize="11sp" 
      android:textStyle="bold" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="Menge :" 
      android:textSize="9sp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/list_warenKorb_menge" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="sldjq" 
      android:textSize="9sp" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="Preis :" 
      android:textSize="9sp" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/list_warenKorb_preis" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="5dp" 
      android:text="sldjq" 
      android:textSize="9sp" /> 
    </LinearLayout> 
</LinearLayout> 

<ImageView 
    android:id="@+id/list_warenKorb_foto" 
    android:layout_width="70dp" 
    android:layout_height="70dp" 
    android:layout_marginLeft="120dp" 
    android:scaleType="centerCrop" 
    android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

Shop

Basket

+0

你在正确的ImageView被切断。你想适合ImageView吗? –

+0

@罗珊珊是的,我希望它仍然不会像第二张图片所示那样来回走动。第二项的笔记本电脑参考资料(蓝色)比第一项短!这就是为什么图片离左边太近了!我希望它始终固定在右侧 – user3816569

+0

请参阅我的回答下方的 –

回答

1

你应该使用RelativeLayout,尝试下面的布局,使图像适应的权利,不切断 custom_row_shop.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/list_foto" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <TextView 
       android:id="@+id/list_ref" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:text="Ref Artikel :" 
       android:textColor="#2383c4" 
       android:textSize="11sp" 
       android:textStyle="bold" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:text="Betriebssytem :" 
       android:textSize="9sp" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/list_betriebssystem" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:text="sldjq" 
       android:textSize="9sp" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:text="Prozessor :" 
       android:textSize="9sp" 
       android:textStyle="bold" /> 



      <TextView 
        android:id="@+id/list_prozessor" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="sldjq" 
        android:textSize="9sp" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Grafikkarte :" 
        android:textSize="9sp" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/list_grafikkarte" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="sldjq" 
        android:textSize="9sp" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="RAM :" 
        android:textSize="9sp" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/list_arbeitsspeicher" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="sldjq" 
        android:textSize="9sp" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="Festplatte :" 
        android:textSize="9sp" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/list_festplatte" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_margin="5dp" 
        android:text="sldjq" 
        android:textSize="9sp" /> 
      </LinearLayout> 
     </LinearLayout> 

     <ImageView 
      android:id="@+id/list_foto" 
      android:layout_width="90dp" 
      android:layout_height="90dp" 
      android:layout_marginLeft="40dp" 
      android:layout_marginTop="20dp" 
      android:scaleType="centerCrop" 
      android:layout_alignParentRight="true" 
      android:src="@drawable/ic_launcher" /> 

    </RelativeLayout> 

custom_row_basket.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@+id/list_warenKorb_foto" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/list_warenKorb_ref" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:text="Ref Artikel :" 
       android:textColor="#2383c4" 
       android:textSize="11sp" 
       android:textStyle="bold" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:text="Menge :" 
       android:textSize="9sp" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/list_warenKorb_menge" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:text="sldjq" 
       android:textSize="9sp" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:text="Preis :" 
       android:textSize="9sp" 
       android:textStyle="bold" /> 

      <TextView 
       android:id="@+id/list_warenKorb_preis" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_margin="5dp" 
       android:text="sldjq" 
       android:textSize="9sp" /> 
     </LinearLayout> 
    </LinearLayout> 

    <ImageView 
     android:id="@+id/list_warenKorb_foto" 
     android:layout_width="70dp" 
     android:layout_height="70dp" 
     android:layout_marginLeft="120dp" 
     android:scaleType="centerCrop" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 
+0

这解决了我的问题!谢谢先生:D – user3816569

0

问题是您的图片有时会推到最右边?这是它对我来说是什么,但不知道。如果是这样,请暂时在TextView上放一些背景颜色,看看它们是否占用了太多空间。

+0

文字需要太多空间!任何提示如何避免这一点?并且您可以看到不适合ImageView的图片!有一些削减..我如何可以在ImageView中正确显示它们。同样在第二张照片中,第二个项目的参考(蓝色)比第一个项目短得多!这就是为什么第一张照片不能出现!但第二张照片太靠近左边了!我如何将imageview设置为静止的地方,以免它来回走动!我希望我足够清楚 – user3816569

0

试试这个,

使用android:scal ETYPE = “fitXY”

<ImageView 
    android:id="@+id/list_foto" 
    android:layout_width="90dp" 
    android:layout_height="90dp" 
    android:layout_marginLeft="40dp" 
    android:layout_marginTop="20dp" 
    android:scaleType="fitXY" 
    android:src="@drawable/placeholder" /> 

Java类:

Picasso.with(this.getContext()).load(lFoto).into(foto);