android - 将屏幕大小的一半的线性布局水平对齐在屏幕的正中心

标签 android android-layout android-xml

问题的标题说明了一切,我正在尝试制作如图所示的 View ,这里的中心部分应该正好是屏幕的一半大小,并且应该出现在屏幕的中央。 the sketch of my view

我正在使用 layout_weight 和 weightsum 并避免左右填充:

    <LinearLayout
    android:id="@+id/OuterlinLayout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="4" >
     <LinearLayout
        android:id="@+id/containerLayout1"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="horizontal" />
     <LinearLayout
        android:id="@+id/GlobalLayout"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_weight="2"
        android:orientation="vertical" >contens of main view</LinearLayout>
     <LinearLayout
        android:id="@+id/containerLayout2"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_weight="1"
        android:orientation="horizontal" >

但它没有显示我想要的...我犯了什么错误?

最佳答案

你的 OuterlinLayout LinearLayout 应该有 android:orientation="horizo​​ntal" 而不是垂直的,它的所有 child 都应该有 android:layout_width="0dp"

关于android - 将屏幕大小的一半的线性布局水平对齐在屏幕的正中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17198425/

相关文章:

android - 检测 GridView 滚动速度 - Android

android - 滚动条未在 RecyclerView 中显示

android-layout - Android 中带倒计时器的进度条

android - 如何让Button在底部重叠CardView

Android自定义布局属性 "reference attribute"格式?

android - 选择 Spinner 项时如何阻止 ScrollView 向上滚动?

android-如何将 View 保存到 SD 卡

android - 选中时 NavigationView 的颜色

android - android studio 中 activity_main.xml 和 content_main.xml 之间的确切区别是什么

android - 当内容无法容纳时,如何创建默认形状为正方形且高度可自动调整的 TextView?