在我的应用程序中,我有主要布局,线性布局为父级和子级滚动视图,在此滚动视图中,我有另一个线性布局。
例子是
LinearLayout->
ScrollView->
LinearLayout->(在此设置背景图片)
因此,如果背景是非常高的分辨率,它会扩展很多,所以我调整了背景,因此它可以在大多数设备上工作,因为扩展减少但是仍然在具有不同屏幕尺寸的设备中有很大的差异。所以问题仍然存在,处理这个问题的正确方法是什么?
什么屏幕看起来像分辨率为背景图像(729 * 1296)Background Image(729*1296)
在使用分辨率(400 * 711)调整背景图像大小并在xxhdpi设备上运行后,它看起来像这样。 Background image(400*711)
所以现在我有一个小卷轴。哪个好,但在不同的设备上应用可能很棘手,并且布局大小有所不同。
我想要在所有设备上看起来像这样。 Background Image(What i want)
如果没有任何背景图片的大小调整,我希望我的布局在所有设备中看起来都像这样,只有3个内部布局(图片,音频,视频)应该是可见的,应该滚动。
这是布局XML文件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context=".StartActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/pg5"
android:orientation="vertical"
android:weightSum="5"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
<LinearLayout
android:id="@+id/gb_text"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.55"
android:gravity="center|top"
android:orientation="vertical"
android:weightSum="3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.2"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center|top"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center|top"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Duplicate Files Remover"
android:textColor="@android:color/white"
android:textSize="@dimen/DuplicateFileRemovertext" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal"></LinearLayout>
</LinearLayout>
</LinearLayout>
<com.intrusoft.sectionedrecyclerviewapp.CircularProgressBar
android:id="@+id/circularProgress"
android:layout_width="@dimen/circularprogresswidth"
android:layout_height="@dimen/circularprogressheight"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/circularprogresstopmargin" />
<TextView
android:id="@+id/gb_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="TextView"
android:textColor="@android:color/white"
android:textSize="@dimen/totalavailablesize" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.45"
android:orientation="vertical"
android:weightSum="5">
<LinearLayout
android:id="@+id/scanimages_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="3dp"
android:layout_weight="1"
android:weightSum="2">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="12dp">
<LinearLayout
android:id="@+id/piccardlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bluelayout"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal"
android:paddingLeft="8dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/picicon"
android:scaleType="fitXY"
app:riv_corner_radius="12dip"
app:riv_mutate_background="true"
app:riv_oval="false"
app:riv_tile_mode="clamp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:paddingLeft="8dp"
android:text=" Pictures"
android:textColor="@android:color/white"
android:textSize="@dimen/Scanpicturestext" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:id="@+id/scanaudio_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="3dp"
android:layout_weight="1"
android:weightSum="2">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="12dp">
<LinearLayout
android:id="@+id/audiocardlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/purplelayout"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal"
android:paddingLeft="8dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/imageView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="1dp"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/playicon"
android:scaleType="fitXY"
app:riv_corner_radius="12dip"
app:riv_mutate_background="true"
app:riv_oval="false"
app:riv_tile_mode="clamp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:paddingLeft="8dp"
android:text=" Audios"
android:textColor="@android:color/white"
android:textSize="@dimen/Scanaudiostext" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:id="@+id/scanvideos_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="3dp"
android:layout_weight="1"
android:weightSum="2">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="12dp">
<LinearLayout
android:id="@+id/videocardlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/redlayout"
android:orientation="horizontal"
android:weightSum="2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal"
android:paddingLeft="8dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/imageView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="1dp"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/vidicon"
android:scaleType="fitCenter"
app:riv_corner_radius="12dip"
app:riv_mutate_background="true"
app:riv_oval="false"
app:riv_tile_mode="clamp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:paddingLeft="8dp"
android:text="Videos"
android:textColor="@android:color/white"
android:textSize="@dimen/Scanvideostext" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:id="@+id/scandocs_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="3dp"
android:layout_weight="1"
android:weightSum="2">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
app:cardCornerRadius="12dp">
<LinearLayout
android:id="@+id/doccardlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/greenlayout"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:orientation="horizontal"
android:paddingLeft="8dp">
<com.makeramen.roundedimageview.RoundedImageView
android:id="@+id/imageView5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="1dp"
android:layout_marginStart="0dp"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:layout_marginEnd="0dp"
android:layout_marginRight="0dp"
android:layout_marginBottom="0dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="@drawable/docxicon"
android:scaleType="fitXY"
app:riv_corner_radius="12dip"
app:riv_mutate_background="true"
app:riv_oval="false"
app:riv_tile_mode="clamp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1.5"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/textView5"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:paddingLeft="8dp"
android:text="Docs"
android:textColor="@android:color/white"
android:textSize="@dimen/Scandocumentstext" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
我刚看了一下布局代码。它显示了这种行为,因为您将背景分配给高度为wrap_content的线性布局。因此线性布局的大小随着提供的背景而变化。您应该将背景放在imageview中。
但是,在我看来,您应该更改布局的整体层次结构。它应该是这样的:
RelativeLayout
ImageView
ScrollView
LinearLayout-> this will contain your code, which you want to scroll
一个简单的结构xml就像这样,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:src="@drawable/background"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Your Layout code goes here -->
</LinearLayout>
</ScrollView>
</RelativeLayout>