在每一行中,我都希望按此顺序
我对单行使用以下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="60dp"
android:padding="4dp">
<TextView
android:id="@+id/time"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="18:00"
android:textAlignment="center" />
<ImageView
android:id="@+id/homeTeamLogo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<ImageView
android:id="@+id/awayTeamLogo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
<TextView
android:id="@+id/homeTeam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/homeTeamLogo"
android:layout_toLeftOf="@id/time"
android:layout_toRightOf="@id/homeTeamLogo"
android:layout_toStartOf="@id/time"
android:paddingLeft="4dp"
android:text="home team" />
<TextView
android:id="@+id/awayTeam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/time"
android:layout_toLeftOf="@id/awayTeamLogo"
android:layout_toRightOf="@id/time"
android:gravity="right"
android:layout_toStartOf="@id/awayTeamLogo"
android:paddingRight="4dp"
android:text="away team" />
</RelativeLayout>
在Android Studio的预览中,我看到了正确的行为:
我不明白原因,请有人帮助我吗?
在我的viewHolder中我在bind方法中设置了所有数据,我使用glide for images:
public void bind(RequestManager glide, final Match match) {
mTimeTV.setText(DateHelper.getMatchTime(match.getDate()));
glide.load(match.getHomeTeamLogoPath())
.into(mHomeTeamLogoIV);
glide.load(match.getAwayTeamLogoPath())
.into(mAwayTeamLogoIV);
mHomeTeamTV.setText(match.getHomeTeamName());
mAwayTeamTV.setText(match.getAwayTeamName());
}
答案 0 :(得分:0)
尝试将{xml}替换为Constraint Layout:
<android.support.constraint.ConstraintLayout 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="wrap_content"
android:padding="4dp">
<ImageView
android:id="@+id/homeTeamLogo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/homeTeam"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:paddingLeft="4dp"
android:text="home team"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/time"
app:layout_constraintStart_toEndOf="@+id/homeTeamLogo"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/time"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="18:00"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/awayTeam"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:gravity="right"
android:paddingRight="4dp"
android:text="away team"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/awayTeamLogo"
app:layout_constraintStart_toEndOf="@+id/time"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/awayTeamLogo"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />