如何在 ScrollView 底部对齐线性广告布局?
Posted
技术标签:
【中文标题】如何在 ScrollView 底部对齐线性广告布局?【英文标题】:How to align linear ad layout at the bottom in the ScrollView? 【发布时间】:2021-10-07 10:56:58 【问题描述】:请看我的代码。我想在页面底部设置最后一个线性布局。如果我通过它到 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_
android:layout_
android:orientation="vertical"
android:background="@drawable/backgroundmain"
tools:context=".TeamInfoAll">
<LinearLayout
android:layout_
android:layout_
android:orientation="vertical">
<LinearLayout
android:layout_
android:layout_
android:padding="10dp">
<androidx.cardview.widget.CardView
android:id="@+id/topcard"
android:layout_
android:layout_
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_
android:layout_
android:src="@drawable/aboutbackground"
android:textAlignment="center"/>
</androidx.cardview.widget.CardView>
</LinearLayout>
<GridLayout
android:id="@+id/mainGrid"
android:layout_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
android:layout_alignParentBottom="true"
android:layout_marginTop="32dp"
android:gravity="bottom"
android:orientation="vertical"
tools:ignore="ObsoleteLayoutParam" />
</LinearLayout>
【问题讨论】:
【参考方案1】:试试这个
<?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_
android:layout_
android:orientation="vertical">
<ScrollView
android:id="@+id/scrollView2"
android:layout_
android:layout_
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_
android:layout_
android:orientation="vertical">
<LinearLayout
android:layout_
android:layout_
android:padding="10dp">
<androidx.cardview.widget.CardView
android:id="@+id/topcard"
android:layout_
android:layout_
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_
android:layout_
android:src="@drawable/aboutbackground"
android:textAlignment="center" />
</androidx.cardview.widget.CardView>
</LinearLayout>
<GridLayout
android:id="@+id/mainGrid"
android:layout_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
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_
android:layout_
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 底部对齐线性广告布局?的主要内容,如果未能解决你的问题,请参考以下文章