создание настраиваемого списка в Android, показывающего трек автобуса - PullRequest
0 голосов
/ 17 мая 2018

как я могу сделать макет, который выглядит следующим образом image в Android, используя вид списка.Я делаю систему слежения за многими автобусами.Если автобус пересечет локацию, круг станет зеленым, иначе он будет красным. Мне нужна вертикальная линия, длина которой зависит от количества остановок для шины. линия должна проходить через центр окружностей. Вот файл listBusStops.xml`

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TableRow
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:layout_marginBottom="30dp">
        <ImageView
            android:id="@+id/ivstatus"
            android:layout_width="30dp"
            android:layout_height="30dp"/>
        <TextView
            android:layout_marginStart="5dp"
            android:gravity="center_vertical"
            android:id="@+id/tvname"
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            />

    </TableRow>
</RelativeLayout>

`

здесь класс custom_list, который я использую `

class Custom_list extends ArrayAdapter {
private final Activity context;
   private final Integer imageid;
   ArrayList<String> list;
   ArrayList<String> status;
public Custom_list(Activity context, ArrayList<String> list, ArrayList<String> status, Integer imageid) {
    super(context, R.layout.list_bus_stops,Track_any_bus.stop_name);

    this.context=context;
    this.list = list;
    this.imageid=imageid;
    this.status = status;
}

public View getView (int position, View view, ViewGroup parent)
{
    LayoutInflater inflater = context.getLayoutInflater();
    View rowview = inflater.inflate(R.layout.list_bus_stops,null,true);// ALL LAYOUT RESOURSE OF list_bus_stops SAVED TO THIS VIEW(rowview)
    TextView textView =  rowview.findViewById(R.id.tvname);//
    ImageView imageView = rowview.findViewById(R.id.ivstatus);
    textView.setText(Track_any_bus.stop_name.get(position));
    if(Track_any_bus.status.get(position).equalsIgnoreCase("yes")) {
        imageView.setImageResource(R.drawable.circle_green);
    }
    else {
        imageView.setImageResource(R.drawable.circle_red);
    }
    return rowview;
}

`

спасибо за ваше время.

1 Ответ

0 голосов
/ 17 мая 2018

Вот демонстрационный рабочий код, пожалуйста, посмотрите, надеюсь, он вам поможет

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:orientation="vertical">

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nested_scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        android:scrollingCache="true">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_marginLeft="18dp"
                android:layout_marginStart="18dp"
                android:gravity="center_horizontal"
                android:orientation="vertical">

                <View
                    android:layout_width="1dp"
                    android:layout_height="match_parent"
                    android:layout_centerHorizontal="true"
                    android:background="#D3D3D3" />

                <ImageView
                    android:layout_width="10dp"
                    android:layout_height="10dp"
                    android:layout_marginTop="44dp"
                    android:tint="#000000"
                    app:srcCompat="@drawable/shape_round_solid" />

            </RelativeLayout>
            <android.support.v7.widget.CardView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="1dp"
                app:cardCornerRadius="5dp"
                app:cardElevation="12dp">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="8dp"
                    android:layout_marginRight="8dp"
                    android:layout_marginTop="8dp"
                    android:background="#ffff"

                    >


                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:orientation="vertical">
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:background="#800000"
                            android:layout_marginTop="2dp"
                            android:layout_marginBottom="2dp"
                            android:layout_height="1dp"></LinearLayout>
                        <TextView
                            android:id="@+id/noteTitle"
                            android:textColor="#ffffff"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="Title"
                            android:background="#000000 "
                            android:textSize="20dp" />
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:background="#800000"
                            android:layout_marginTop="2dp"
                            android:layout_marginBottom="2dp"
                            android:layout_height="1dp"></LinearLayout>
                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content">

                            <TextView
                                android:layout_width="120dp"
                                android:layout_height="wrap_content"
                                android:layout_marginLeft="18dp"
                                android:textSize="14dp"
                                android:textColor="#000080"
                                android:text="Text-Preview"/>
                            <TextView
                                android:id="@+id/textPreview"
                                android:textSize="14dp"
                                android:textColor="#000080"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginLeft="50dp"
                                android:layout_marginTop="5dp"
                                android:text="Sample Text"
                                />
                        </LinearLayout>
                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content">
                            <TextView
                                android:layout_height="wrap_content"
                                android:textSize="14dp"
                                android:textColor="#000080"
                                android:layout_marginLeft="18dp"
                                android:layout_width="120dp"
                                android:text="Last Modified"/>
                            <TextView
                                android:id="@+id/lastModified"
                                android:textColor="#000080"
                                android:layout_width="wrap_content"
                                android:textSize="14dp"
                                android:layout_marginLeft="50dp"
                                android:layout_height="wrap_content"
                                android:layout_marginStart="15dp"
                                android:layout_marginTop="5dp"
                                android:text="12/4/2018"
                                />
                        </LinearLayout>



                    </LinearLayout>

                </RelativeLayout>

            </android.support.v7.widget.CardView>

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...