代码之家  ›  专栏  ›  技术社区  ›  Gustavo Moreira Vieira

安卓工作室-填补剩余空白(高度?)

  •  0
  • Gustavo Moreira Vieira  · 技术社区  · 6 年前

    我有这个: Application

    我想抓取浅蓝色文本( code )并使其自动填充空白(如果有),如: example (可以是空白文本)。

    要调整大小的文本代码(第二个文本视图,除非您可以调整布局的大小):

        <!-- 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>
    

    所有东西都在垂直方向的线性布局中,在这些布局之前有更多的布局,但我相信这些才是最重要的。

    有没有可能在不指定dp编号的情况下自动填充手机上的空白?

    整体编码(我打算自动调整第一个线性布局的大小,直到 将填充所有剩余的空白,并且不会重叠 其他布局)

    编辑 :多亏了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>
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Rockney    6 年前

    可以使用布局权重。它指定视图的额外空间大小。 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>