我有这个:Application
我想抓住浅蓝色文本(code)并使其自动填充空白区域(如果有),如下所示:example(可以是空白文本)。 / p>
要调整大小的文本代码(第二个TextView,除非您可以调整布局大小):
<!-- Info -->
<LinearLayout
android:id="@+id/personalAppLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/backgroundColor">
<TextView
android:id="@+id/descriptionTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/homepage_title"
android:textAlignment="center"
android:textStyle="bold"
android:layout_marginTop="@dimen/activity_vertical_margin"/>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/homepage_description"
android:textAlignment="center"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"/>
</LinearLayout>
<!-- Greyish Line -->
<View
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:background="@color/backgroundColorDark" />
这是图片的代码:Images
<!-- Info -->
<LinearLayout
android:id="@+id/personalAppLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/backgroundColor">
<TextView
android:id="@+id/descriptionTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/homepage_title"
android:textAlignment="center"
android:textStyle="bold"
android:layout_marginTop="@dimen/activity_vertical_margin"/>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/homepage_description"
android:textAlignment="center"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"/>
</LinearLayout>
底部导航代码:Bottom Navigation
<!-- Bottom Navigation -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
所有东西都在一个垂直方向的LinearLayout中,在这些之前有更多的布局,但我相信这些是重要的。
是否可以自动填充手机上的空白区域而无需指定多个dp&#39;
代码作为一个整体(我打算自动调整第一个LinearLayout的大小,直到 所有剩余的空白空间都被填满,而不会重叠任何空白空间 其他布局)
编辑 :现在已更改为完整的工作代码,感谢Rockney
<?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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<!-- Info -->
<LinearLayout
android:id="@+id/personalAppLayout"
android:layout_width="match_parent"
<!-- Previously android:layout_height="wrap_content" and without a weight -->
android:layout_height="0dp"
android:weight="1"
android:orientation="vertical"
android:background="@color/backgroundColor">
<TextView
android:id="@+id/descriptionTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/homepage_title"
android:textAlignment="center"
android:textStyle="bold"
android:layout_marginTop="@dimen/activity_vertical_margin"/>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/homepage_description"
android:textAlignment="center"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"/>
</LinearLayout>
<!-- Greyish Line -->
<View
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:background="@color/backgroundColorDark" />
<!-- Social Media -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:orientation="horizontal"
android:background="@color/backgroundColor"
android:gravity="center" >
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="@dimen/activity_horizontal_margin"
android:background="@drawable/linkedin_logo" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="@dimen/activity_horizontal_margin"
android:background="@drawable/facebook_logo" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="@dimen/activity_horizontal_margin"
android:background="@drawable/twitter_logo" />
</LinearLayout>
<!-- Greyish Line -->
<View
android:layout_width="match_parent"
android:layout_height="0.1dp"
android:background="@color/backgroundColorDark" />
<!-- Bottom Navigation -->
<RelativeLayout
android:layout_width="match_parent"
<!-- Previously android:layout_height="match_parent" -->
android:layout_height="60dp" >
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/navigation"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</LinearLayout>
答案 0 :(得分:0)
您可以使用布局权重。它指定视图中有多少额外空间。 you can read more about in this stackoverflow post.您需要将布局更改为此。
<LinearLayout
android:id="@+id/personalAppLayout"
android:layout_width="match_parent"
android:layout_height="0dp”
android:orientation="vertical"
android:layout_weight=“1”
android:background="@color/backgroundColor">
<TextView
android:id="@+id/descriptionTitle"
android:layout_width="match_parent"
android:layout_weight=“1”
android:layout_height="0dp"
android:text="@string/homepage_title"
android:textAlignment="center"
android:textStyle="bold"
android:layout_marginTop="@dimen/activity_vertical_margin"/>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/homepage_description"
android:textAlignment="center"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginBottom="@dimen/activity_vertical_margin"/>
</LinearLayout>