1

内部でビュータグを使用していますPercentRelativeLayout。プログラムでは実行できないそれぞれのタグに背景色を設定する必要があります。

<android.support.percent.PercentRelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:id="@+id/leaderboardRowRelativeLayout"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent">

    <View
        android:id="@+id/percentile_scored"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_widthPercent="50%"
        app:layout_heightPercent="15%"
        />

    <View
        android:id="@+id/percentile_left_scoring"
    android:layout_width="0dp"
    android:layout_height="0dp"
        app:layout_widthPercent="50%"
        app:layout_heightPercent="15%"
        android:layout_toRightOf="@+id/percentile_scored"
    />

背景を設定しようとする場所:

  if(String.valueOf(userId).equals(leaderBoardDb.getUserId())){
                leaderboardFriendsViewHolder.percent_scored.setBackgroundColor(ContextCompat.getColor(getApplicationContext(),R.color.leaderboard_user_color));

            }else {
                leaderboardFriendsViewHolder.percent_scored.setBackground(ContextCompat.getDrawable(getApplicationContext(),R.drawable.leaderboard_row_color));
            }
4

1 に答える 1