2016-11-09 37 views
1

我試圖建立這個自定義行對我的ListView。通過Photoshop中的魔法在這裏就是我試圖完成:定製行的列表視圖

enter image description here

但是當我跑我的列表視圖,它是走出這樣的:

enter image description here

任何人的幫助我弄清楚我在做什麼錯誤的觀點?

這裏是我的row.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" 
    android:padding="5dp"> 

    <!-- ListRow Left sied Thumbnail image --> 
    <LinearLayout 
     android:id="@+id/thumbnail" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true"> 

     <ImageView 
      android:id="@+id/list_image" 
      android:layout_width="64dp" 
      android:layout_height="64dp" 
      android:layout_alignParentRight="true" 
      android:background="@color/COLOR_GREY" /> 
    </LinearLayout> 

    <!-- Item Name --> 
    <TextView 
     android:id="@+id/txtItemName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@+id/thumbnail" 
     android:layout_toRightOf="@+id/thumbnail" 
     android:text="Item Name" 
     android:textColor="#040404" 
     android:textSize="15dip" 
     android:textStyle="bold" 
     android:typeface="sans" /> 

    <!-- progress count --> 
    <TextView 
     android:id="@+id/txtProgress" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/thumbnail" 
     android:layout_alignLeft="@+id/thumbnail" 
     android:text="Item Name" 
     android:textColor="#040404" 
     android:textSize="15dip" 
     android:textStyle="bold" 
     android:typeface="sans" /> 

    <!-- Retry button --> 
    <Button 
     android:id="@+id/btnRetry" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/txtItemName" 
     android:layout_toRightOf="@id/txtItemName" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="5dp" 
     android:text="Retry" /> 

    <!-- Delete button --> 
    <Button 
     android:id="@+id/btnDelete" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/btnRetry" 
     android:layout_toRightOf="@id/btnRetry" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="5dp" 
     android:text="Delete" /> 

    <!-- ProgressBar --> 
    <ProgressBar 
     style="?android:attr/progressBarStyleHorizontal" 
     android:layout_below="@id/txtItemName" 
     android:layout_alignLeft="@id/txtItemName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/progressBarItem" /> 

</RelativeLayout> 
+0

首先,'RelativeLayout'不使用「orientation」,LinearLayout',那麼當你引用訪問它的ID,當你不使用'+'符號的觀點,它只是用來創建一個新的ID。所以首先我會解決這個問題。而你使用的是全寬與製作等元素出現在屏幕 –

回答

1

這主要是因爲做你的畫面佈局,只需要以使它們看起來更好地與按鈕來改變。

在RelativeLayout的,你不需要使用方向 和文字使用SP的代替

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/row" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:baselineAligned="false" 
    android:gravity="center_vertical"> 

<!-- ListRow Left sied Thumbnail image --> 

<ImageView 
    android:id="@+id/list_image" 
    android:layout_width="64dp" 
    android:layout_height="64dp" 
    android:layout_centerVertical="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    app:srcCompat="@mipmap/ic_launcher" /> 

<!-- Item Name --> 
<TextView 
    android:id="@+id/txtItemName" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/list_image" 
    android:layout_toEndOf="@+id/list_image" 
    android:text="Item Name" 
    android:textColor="#040404" 
    android:textSize="15dip" 
    android:textStyle="bold" 
    android:typeface="sans" /> 

<!-- progress count --> 
<TextView 
    android:id="@+id/txtProgress" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:text="100" 
    android:textColor="#040404" 
    android:textSize="15sp" 
    android:textStyle="bold" 
    android:typeface="sans" /> 

<!-- Retry button --> 
<Button 

    android:id="@+id/btnRetry" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@id/btnDelete" 
    android:layout_toStartOf="@+id/btnDelete" 
    android:text="Retry" /> 

<!-- Delete button --> 
<Button 
    android:id="@+id/btnDelete" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:text="Delete" /> 

<!--&lt;!&ndash; ProgressBar &ndash;&gt;--> 
<ProgressBar 
    style="?android:attr/progressBarStyleHorizontal" 
    android:layout_below="@id/txtItemName" 
    android:layout_toLeftOf="@+id/txtProgress" 
    android:layout_toStartOf="@+id/txtProgress" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/list_image" 
    android:layout_toEndOf="@+id/list_image" 
    android:progress="100" 
    android:id="@+id/progressBarItem" /> 

你可以找到其他的技巧如何與佈局工作做小部分佈局並在stackoverflow中搜索它們,然後你可以學習如何做更大的佈局。因爲之前你確實需要將一些組件包裝到線性佈局中,但現在使用Android Studio 2.2,您可以使用ConstraintLayout

+0

對不起,使用你的佈局現在什麼都沒有。 –

+0

我檢查了設計頁面,它的工作原理。你怎麼試試它? – aleksandrbel

0

爲什麼你使用裏面LinelarLayout ImageView的?

檢查:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:padding="5dp"> 

    <!-- ListRow Left sied Thumbnail image --> 

    <ImageView 
     android:id="@+id/list_image" 
     android:layout_width="64dp" 
     android:layout_height="64dp" 
     android:layout_alignParentLeft="true" 
     android:background="@color/COLOR_GREY" /> 

    <!-- Item Name --> 
    <TextView 
     android:id="@+id/txtItemName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/list_image" 
     android:layout_toRightOf="@id/list_image" 
     android:text="Item Name" 
     android:textColor="#040404" 
     android:layout_marginLeft="10dp" 
     android:textSize="15sp" 
     android:textStyle="bold" 
     android:typeface="sans" /> 

    <!-- progress count --> 
    <TextView 
     android:id="@+id/txtProgress" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="5dp" 
     android:layout_alignBottom="@id/list_image" 
     android:text="Item Name" 
     android:textColor="#040404" 
     android:textSize="15sp" 
     android:textStyle="bold" 
     android:typeface="sans" /> 


    <!-- Delete button --> 
    <Button 
     android:id="@+id/btnDelete" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/btnRetry" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="5dp" 
     android:text="Delete" /> 

    <!-- Retry button --> 
    <Button 
     android:id="@+id/btnRetry" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/txtItemName" 
     android:layout_toLeftOf="@id/btnDelete" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="5dp" 
     android:text="Retry" /> 

    <!-- ProgressBar --> 
    <ProgressBar 
     style="?android:attr/progressBarStyleHorizontal" 
     android:layout_alignBottom="@id/list_image" 
     android:layout_toRightOf="@id/list_image" 
     android:layout_marginLeft="10dp" 
     android:layout_marginRight="5dp" 
     android:layout_toLeftOf="@id/txtProgress" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/progressBarItem" /> 

</RelativeLayout> 

另外,不要忘記,TEXTSIZE應在SP

如果要更改按鈕大小 - 只需更換:

android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 

,並把您的自定義寬度和高度在DP一樣:

android:layout_width="25dp" 
    android:layout_height="25dp" 
+1

,並記住,你必須爲不同屏幕尺寸的新佈局ImageView的佈局,因爲你選擇設置一個固定的寬度和高度 –

+0

@AhmadAlsanie是的,謝謝!) –

+0

對不起,你用什麼佈局現在看來。 –