在的LinearLayout ImageView的权重 [英] imageview weights in linearlayout
本文介绍了在的LinearLayout ImageView的权重的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:minWidth="100dp" >
<TextView
android:id="@+id/txt_what_way"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="4"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="3">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher"/>
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="3">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher"/>
</LinearLayout>
</LinearLayout>
我想,它看起来像:
I want that it looks like:
的TextView - 40宽%,分屏的ImageView - widht的30%,分屏的ImageView - 宽度的30%。
TextView - 40% of width, Layout with ImageView - 30% of widht, Layout with ImageView - 30% of width.
但输出是:
TextViewImageViewImageView ----------------自由空间---------------------------- ------
TextViewImageViewImageView----------------free space----------------------------------
感谢您的帮助!
- EDITED
-- EDITED
在编程的方式完成它
推荐答案
使用Android:weightSum =10,在你的情况和
使用Android:背景到位的android:SRC,这个替换您的XML文件
Use android:weightSum="10" in your case and Use android:background in place of android:src , replace your xml file with this
<TextView
android:id="@+id/txt_what_way"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="4"
android:text="test"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="20dp"
android:layout_weight="3"
android:background="@drawable/s1"/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="20dp"
android:layout_weight="3"
android:background="@drawable/s1"/>
</LinearLayout>
您可能会得到扭曲的图像
You might get distorted image
这篇关于在的LinearLayout ImageView的权重的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文