如何把50%的宽度 [英] How to put 50% for width

查看:133
本文介绍了如何把50%的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在水平方向和2 ImageView的一个的LinearLayout,我想做出ImagesView宽度上填满屏幕的50%,在每一个手机或平板电脑diferent大小的工作。

事情是这样的:

  + ------------- +
 | _____________ |
 | | |
 | 50%| 50%|
 | | |
 | ------------- |
 | |
 + ------------- +

迄今为止最好的:

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:比重=中心
    机器人:方向=横向>
        < ImageView的
            机器人:ID =@ + ID / logo_c
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:SRC =@绘制/ logo_animado/>        < ImageView的
            机器人:ID =@ + ID / logo_t
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT
            机器人:SRC =@绘制/ logo_animado2/>
< / LinearLayout中>


解决方案

编写以下code做,在里面的两个视图的LinearLayout

 的android:layout_width =0dp
layout_weight =1

I have a LinearLayout in horizontal orientation and 2 ImageView and I want to make that ImagesView fill 50% of the screen on width, to work in every cellphone or tablet with diferent sizes.

Something like this:

 +-------------+   
 |_____________|     
 |      |      |  
 | 50%  | 50%  |  
 |      |      |   
 |-------------|
 |             |
 +-------------+

Best so far:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center"
    android:orientation="horizontal" >


        <ImageView
            android:id="@+id/logo_c"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/logo_animado" />

        <ImageView
            android:id="@+id/logo_t"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/logo_animado2" />


</LinearLayout>

解决方案

Write following code to do that in both views inside LinearLayout.

android:layout_width="0dp"
layout_weight="1"

这篇关于如何把50%的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆