我曾试图给 ScrollView 内的 child 负 marginTop 值。 但它并没有像预期的那样对齐。它隐藏在 ScrollView 上方的布局下方。我想实现我在截图中提到的设计。特别是 Logo 在横幅中 float 了 75%,在横幅下方 float 了 25%。谁能对此提出您的想法。
我正在使用最新的 android 支持设计库。
最佳答案
我刚刚实现了相同的布局设计。 我想和你分享。希望对您有所帮助。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<LinearLayout
android:id="@+id/layoutActionbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/actionbar_background"
android:orientation="horizontal">
<TextView
android:id="@+id/txtBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@mipmap/back" />
<TextView
android:id="@+id/lblHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center"
android:layout_margin="5dp"
android:text=""
android:textColor="#FFFFFF"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<RelativeLayout
android:id="@+id/layoutTop"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@+id/layoutActionbar"
android:background="#F0F0F0"
android:gravity="center">
<TextView
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txtSubTitle"
android:layout_centerHorizontal="true"
android:gravity="center"
android:lines="2"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:text=""
android:textSize="20sp" />
<TextView
android:id="@+id/txtSubTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:lines="2"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:text=""
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/layoutBottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_below="@id/layoutTop">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="22dp"
android:layout_marginStart="22dp"
android:layout_marginTop="40dp"
android:text="ADDITIONAL INFORMATION"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#007DCE" />
<TextView
android:id="@+id/txtDescreiption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="22dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="22dp"
android:layout_marginStart="22dp"
android:layout_marginTop="20dp"
android:text="SOURCES and LINKS"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#007DCE" />
<TextView
android:id="@+id/txtWebsites"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="22dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:autoLink="web"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_above="@id/layoutBottom"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-20dp"
android:adjustViewBounds="true"
android:background="#F0F0F0">
<ImageView
android:id="@+id/favImage"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:src="@mipmap/ic_favourite_selected" />
</LinearLayout>
</RelativeLayout>
关于ScrollView 中的 Android 边距顶部负值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33162980/