如何在 ScrollView 底部对齐线性广告布局?
How to align linear ad layout at the bottom in the ScrollView?
请看我的代码。我想在页面底部设置最后一个线性布局。如果我通过它到 Scrollview 的外部,它就不起作用。任何人都可以帮我解决它吗..我附上了代码。我尝试了不同的组合,但没有用。提前致谢。
<滚动视图
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fillViewport="true"
android:paddingTop="65dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/backgroundmain"
tools:context=".TeamInfoAll">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<androidx.cardview.widget.CardView
android:id="@+id/topcard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="14dp"
app:cardBackgroundColor="#FAFAFA"
app:cardCornerRadius="12dp"
app:cardElevation="8dp"
tools:targetApi="lollipop">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/aboutbackground"
android:textAlignment="center"/>
</androidx.cardview.widget.CardView>
</LinearLayout>
<GridLayout
android:id="@+id/mainGrid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alignmentMode="alignMargins"
android:columnOrderPreserved="false"
android:padding="10dp"
android:columnCount="1"
android:rowCount="6">
<!--Row 1-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView1"
android:layout_width="match_parent"
android:layout_height="60dp"
app:cardBackgroundColor="#4CAF50"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_marginBottom="14dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
app:cardElevation="8dp"
app:cardCornerRadius="12dp"
tools:targetApi="lollipop">
<TextView
android:id="@+id/cardView1Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/Team1"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="25sp"
tools:ignore="RtlCompat" />
</androidx.cardview.widget.CardView>
<!--Row 2-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView2"
android:layout_width="match_parent"
android:layout_height="60dp"
app:cardBackgroundColor="#F44336"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_marginBottom="14dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
app:cardElevation="8dp"
app:cardCornerRadius="12dp"
tools:targetApi="lollipop">
<TextView
android:id="@+id/cardView2Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/Team2"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="25sp"
tools:ignore="RtlCompat" />
</androidx.cardview.widget.CardView>
<!--Row 3-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView3"
android:layout_width="match_parent"
android:layout_height="60dp"
app:cardBackgroundColor="#2196F3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_marginBottom="14dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
app:cardElevation="8dp"
app:cardCornerRadius="12dp"
tools:targetApi="lollipop">
<TextView
android:id="@+id/cardView3Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/Team3"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="22sp"
tools:ignore="RtlCompat" />
</androidx.cardview.widget.CardView>
</GridLayout>
<LinearLayout
android:id="@+id/banner_container1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="32dp"
android:gravity="bottom"
android:orientation="vertical"
tools:ignore="ObsoleteLayoutParam" />
</LinearLayout>
试试这个
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/backgroundmain"
android:fillViewport="true"
android:orientation="vertical"
android:paddingTop="65dp"
app:layout_constraintBottom_toTopOf="@+id/banner_container1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context=".TeamInfoAll">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<androidx.cardview.widget.CardView
android:id="@+id/topcard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="14dp"
app:cardBackgroundColor="#FAFAFA"
app:cardCornerRadius="12dp"
app:cardElevation="8dp"
tools:targetApi="lollipop">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/aboutbackground"
android:textAlignment="center" />
</androidx.cardview.widget.CardView>
</LinearLayout>
<GridLayout
android:id="@+id/mainGrid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alignmentMode="alignMargins"
android:columnCount="1"
android:columnOrderPreserved="false"
android:padding="10dp"
android:rowCount="6">
<!--Row 1-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView1"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="14dp"
app:cardBackgroundColor="#4CAF50"
app:cardCornerRadius="12dp"
app:cardElevation="8dp"
tools:targetApi="lollipop">
<TextView
android:id="@+id/cardView1Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="@string/Team1"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="25sp"
tools:ignore="RtlCompat" />
</androidx.cardview.widget.CardView>
<!--Row 2-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView2"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="14dp"
app:cardBackgroundColor="#F44336"
app:cardCornerRadius="12dp"
app:cardElevation="8dp"
tools:targetApi="lollipop">
<TextView
android:id="@+id/cardView2Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="@string/Team2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="25sp"
tools:ignore="RtlCompat" />
</androidx.cardview.widget.CardView>
<!--Row 3-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView3"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="14dp"
app:cardBackgroundColor="#2196F3"
app:cardCornerRadius="12dp"
app:cardElevation="8dp"
tools:targetApi="lollipop">
<TextView
android:id="@+id/cardView3Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="@string/Team3"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="22sp"
tools:ignore="RtlCompat" />
</androidx.cardview.widget.CardView>
</GridLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/banner_container1"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="ObsoleteLayoutParam" />
</androidx.constraintlayout.widget.ConstraintLayout>
您可以根据需要调整底部布局的高度。
请看我的代码。我想在页面底部设置最后一个线性布局。如果我通过它到 Scrollview 的外部,它就不起作用。任何人都可以帮我解决它吗..我附上了代码。我尝试了不同的组合,但没有用。提前致谢。
<滚动视图
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fillViewport="true"
android:paddingTop="65dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/backgroundmain"
tools:context=".TeamInfoAll">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<androidx.cardview.widget.CardView
android:id="@+id/topcard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="14dp"
app:cardBackgroundColor="#FAFAFA"
app:cardCornerRadius="12dp"
app:cardElevation="8dp"
tools:targetApi="lollipop">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/aboutbackground"
android:textAlignment="center"/>
</androidx.cardview.widget.CardView>
</LinearLayout>
<GridLayout
android:id="@+id/mainGrid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alignmentMode="alignMargins"
android:columnOrderPreserved="false"
android:padding="10dp"
android:columnCount="1"
android:rowCount="6">
<!--Row 1-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView1"
android:layout_width="match_parent"
android:layout_height="60dp"
app:cardBackgroundColor="#4CAF50"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_marginBottom="14dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
app:cardElevation="8dp"
app:cardCornerRadius="12dp"
tools:targetApi="lollipop">
<TextView
android:id="@+id/cardView1Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/Team1"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="25sp"
tools:ignore="RtlCompat" />
</androidx.cardview.widget.CardView>
<!--Row 2-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView2"
android:layout_width="match_parent"
android:layout_height="60dp"
app:cardBackgroundColor="#F44336"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_marginBottom="14dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
app:cardElevation="8dp"
app:cardCornerRadius="12dp"
tools:targetApi="lollipop">
<TextView
android:id="@+id/cardView2Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/Team2"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="25sp"
tools:ignore="RtlCompat" />
</androidx.cardview.widget.CardView>
<!--Row 3-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView3"
android:layout_width="match_parent"
android:layout_height="60dp"
app:cardBackgroundColor="#2196F3"
android:layout_columnWeight="1"
android:layout_rowWeight="1"
android:layout_marginBottom="14dp"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
app:cardElevation="8dp"
app:cardCornerRadius="12dp"
tools:targetApi="lollipop">
<TextView
android:id="@+id/cardView3Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/Team3"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="22sp"
tools:ignore="RtlCompat" />
</androidx.cardview.widget.CardView>
</GridLayout>
<LinearLayout
android:id="@+id/banner_container1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="32dp"
android:gravity="bottom"
android:orientation="vertical"
tools:ignore="ObsoleteLayoutParam" />
</LinearLayout>
试试这个
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@drawable/backgroundmain"
android:fillViewport="true"
android:orientation="vertical"
android:paddingTop="65dp"
app:layout_constraintBottom_toTopOf="@+id/banner_container1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context=".TeamInfoAll">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<androidx.cardview.widget.CardView
android:id="@+id/topcard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="14dp"
app:cardBackgroundColor="#FAFAFA"
app:cardCornerRadius="12dp"
app:cardElevation="8dp"
tools:targetApi="lollipop">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/aboutbackground"
android:textAlignment="center" />
</androidx.cardview.widget.CardView>
</LinearLayout>
<GridLayout
android:id="@+id/mainGrid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alignmentMode="alignMargins"
android:columnCount="1"
android:columnOrderPreserved="false"
android:padding="10dp"
android:rowCount="6">
<!--Row 1-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView1"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="14dp"
app:cardBackgroundColor="#4CAF50"
app:cardCornerRadius="12dp"
app:cardElevation="8dp"
tools:targetApi="lollipop">
<TextView
android:id="@+id/cardView1Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="@string/Team1"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="25sp"
tools:ignore="RtlCompat" />
</androidx.cardview.widget.CardView>
<!--Row 2-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView2"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="14dp"
app:cardBackgroundColor="#F44336"
app:cardCornerRadius="12dp"
app:cardElevation="8dp"
tools:targetApi="lollipop">
<TextView
android:id="@+id/cardView2Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="@string/Team2"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="25sp"
tools:ignore="RtlCompat" />
</androidx.cardview.widget.CardView>
<!--Row 3-->
<androidx.cardview.widget.CardView
android:id="@+id/cardView3"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="14dp"
android:layout_marginRight="14dp"
android:layout_marginBottom="14dp"
app:cardBackgroundColor="#2196F3"
app:cardCornerRadius="12dp"
app:cardElevation="8dp"
tools:targetApi="lollipop">
<TextView
android:id="@+id/cardView3Text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="@string/Team3"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="22sp"
tools:ignore="RtlCompat" />
</androidx.cardview.widget.CardView>
</GridLayout>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="@+id/banner_container1"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="ObsoleteLayoutParam" />
</androidx.constraintlayout.widget.ConstraintLayout>
您可以根据需要调整底部布局的高度。