我有一个很小的线性布局,我必须在里面放入一个imageView和一个textView。我知道这是一种很糟糕的应用程序开发方式。我只是试着测试一下,看看这是否可行。下面的代码只显示了图像视图,而没有显示textView。有什么想法吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="90dp"
android:layout_height="90dp"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:src="@drawable/my_icon" />
</LinearLayout>
</LinearLayout>发布于 2012-08-13 14:51:06
最终的答案是给textView的权重为0,给imageView的权重为1。这样,textView完美地显示了出来,但只占用了它所需的空间,而imageView则占据了其余的空间。Perfect1
发布于 2012-08-13 14:29:06
这取决于您希望它看起来是什么样子。如果您希望将LinearLayout一分为二,那么在您的ImageView集合中
android:layout_weight="1"LinearLayout中的视图与它们的layout_weight成比例地获得空间,所以如果你的ImageView有layout_weight="0",它将获得0比例的视图。
发布于 2012-08-13 14:42:08
你应该像这样使用权重:
LinearLayout中的android:layout_weight="2“
和imageView和textView中的layout_weight="1“
这样两个视图都会占据一半的空间
https://stackoverflow.com/questions/11929078
复制相似问题