android - 布局设置错误

标签 android android-layout

现在我有一个如图所示的布局,只是我想要白色矩形内的蓝色矩形我去填充白色方 block 的整个大小..但是我尝试更改一些设置但没有用。

Xml 是:

    <merge xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   tools:context=".LoginActivity" >


    <!-- Login progress -->

    <LinearLayout
       android:id="@+id/login_status"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="center"
       android:gravity="center_horizontal"
       android:orientation="vertical"
       android:visibility="gone" >

        <ProgressBar
           style="?android:attr/progressBarStyleLarge"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginBottom="8dp" />

        <TextView
           android:id="@+id/login_status_message"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:layout_marginBottom="16dp"
           android:fontFamily="sans-serif-light"
           android:text="@string/login_progress_signing_in"
           android:textAppearance="?android:attr/textAppearanceMedium" />
    </LinearLayout>

    <!-- Login form -->

    <ScrollView
       android:id="@+id/login_form"
       android:layout_width="fill_parent"
       android:layout_height="match_parent"
       android:background="@color/background_color" >



        <LinearLayout
           style="@style/LoginFormContainer"
           android:layout_width="fill_parent"
           android:layout_height="wrap_content"
           android:layout_gravity="center_horizontal"
           android:layout_marginTop="20dp"
           android:background="@color/background_login_color"
           android:orientation="vertical" >

        <LinearLayout
       android:id="@+id/row0"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:background="@drawable/top_logo_repeat"
       android:gravity="center"
       android:orientation="vertical" >

        <ImageView
           android:id="@+id/imageLogo"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:antialias="true"
           android:contentDescription="@string/logoimg"
           android:src="@drawable/logo" />

    </LinearLayout>

            <EditText
               android:id="@+id/username"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:hint="@string/prompt_username"
               android:inputType="textEmailAddress"
                           android:layout_marginTop="20dp"

               android:maxLines="1"
               android:singleLine="true" />

            <EditText
               android:id="@+id/password"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:hint="@string/prompt_password"
               android:imeActionId="@+id/login"
               android:imeActionLabel="@string/action_sign_in_short"
               android:imeOptions="actionUnspecified"
               android:inputType="textPassword"
               android:maxLines="1"
               android:singleLine="true" />

            <CheckBox
               android:id="@+id/checkBox1"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:text="@string/saveCheckBox" />

            <Button
               android:id="@+id/sign_in_button"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:layout_marginTop="16dp"
               android:paddingLeft="32dp"
               android:paddingRight="32dp"
               android:text="@string/action_sign_in_register" />

            <Button
               android:id="@+id/button1"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:layout_toRightOf="@+id/sign_in_button"
               android:layout_weight="0.30"
               android:text="@string/registerButton" />

        </LinearLayout>

    </ScrollView>

</merge>

Screen Layout

最佳答案

您的 linearLayout 已将样式设置为 LoginFormContainer

<LinearLayout
       style="@style/LoginFormContainer"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:layout_gravity="center_horizontal"
       android:layout_marginTop="20dp"
       android:background="@color/background_login_color"
       android:orientation="vertical" >

在这种风格中,很可能设置了边距。因此,LinearLayout 中的所有内容都有边距。

对此的解决方案是从样式中删除边距。 (或者从 LinearLayout 中删除样式。

注意:这也会移除图像下方 editText 等的边距,因为它们也在线性布局中。

解决此问题的解决方案是将其余内容包装在其自己的 LinearLayout 中,并将边距应用于此 LinearLayout

关于android - 布局设置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21042630/

相关文章:

安卓多屏设计

java - Android Studio 中 Seekbars( View )的径向布局

android - eclipse 错误 : Android Library Update error

java - 如何在两个 Activity 的共享首选项中存储时间

android - 使用架构组件导航将数据从单个 Activity 传递到开始目标 fragment

android - 是否可以从导入的 gradle 库中删除一个类?

Android 类扩展 MainActivity 上的 View 和位置

android - 适配器类转换异常从 ListView 中删除页脚 View

android - picasso 加载字节数组

android - RecyclerView 适配器显示的图像多于应有的数量