gpt4 book ai didi

android - 创建带权重的线性布局

转载 作者:太空宇宙 更新时间:2023-11-03 12:57:19 25 4
gpt4 key购买 nike

我正在尝试制作类似的东西 - Android Layout(User Interface)只是我想让第一列的权重为 4,第二列的权重为 2(也有两行),最后一列的权重为 1(也有三行)...问题是自己搞砸了(我复制并粘贴了答案并根据我的需要更改了所有内容,但它一直搞砸了.. =)有什么帮助吗?[代码]

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background_color"
android:orientation="vertical"

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal" >

<TextView
android:id="@+id/textDishes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="@string/dishes"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/imageDishes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>

<View
android:layout_width="fill_parent"
android:layout_height="@dimen/seperator_size"
android:background="@color/seperator" />

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:measureWithLargestChild="true"
android:orientation="horizontal"
android:weightSum="2" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >

<TextView
android:id="@+id/textfood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/food"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/imagefood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>

<View
android:layout_width="fill_parent"
android:layout_height="@dimen/seperator_size"
android:background="@color/seperator" />

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >

<TextView
android:id="@+id/textMalls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/malls"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/imageMalls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>

<View
android:layout_width="fill_parent"
android:layout_height="@dimen/seperator_size"
android:background="@color/seperator" />

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:weightSum="3"
android:orientation="horizontal" >

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>

<View
android:layout_width="fill_parent"
android:layout_height="@dimen/seperator_size"
android:background="@color/seperator" />

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/coupons"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>

<View
android:layout_width="fill_parent"
android:layout_height="@dimen/seperator_size"
android:background="@color/seperator" />

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/markets"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>

</LinearLayout>
[/code]

这就是结果——

enter image description here

结果应该是这样的—— enter image description here有帮助吗??

最佳答案

编辑现在的工作示例

这不是一个完整的答案,因为垂直分隔线仍然不起作用,但希望它能让您朝着正确的方向前进:

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="4"
android:gravity="center"
android:orientation="vertical" >

<TextView
android:id="@+id/textDishes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dishes"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/imageDishes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@color/red" />

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:orientation="horizontal" >

<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >

<TextView
android:id="@+id/textfood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Food"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/imagefood"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>

<View
android:layout_width="5dp"
android:layout_height="fill_parent"
android:background="@color/red"
android:gravity="center" >
</View>

<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >

<TextView
android:id="@+id/textMalls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Malls"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/imageMalls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>

<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@color/red" />

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal" >

<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="App name"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>

<View
android:layout_width="5dp"
android:layout_height="fill_parent"
android:background="@color/red"
android:gravity="center" >
</View>

<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coupons"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>

<View
android:layout_width="5dp"
android:layout_height="fill_parent"
android:background="@color/red"
android:gravity="center" >
</View>

<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Markets"
android:textAppearance="?android:attr/textAppearanceLarge" />

<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>

enter image description here

关于android - 创建带权重的线性布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17680184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com