Giter Site home page Giter Site logo

Comments (10)

krislq avatar krislq commented on June 12, 2024

weight

代码如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView1"
            android:layout_weight="0.5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Weight 0.5"
            android:background="#ff0" />

        <TextView
            android:id="@+id/textView2"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Weight 1"
            android:background="#f00"/>
    </LinearLayout>

</RelativeLayout>

from google_android_book_v2.

snowxwyo avatar snowxwyo commented on June 12, 2024

kris大神这个设的有问题,官方文档说了,weight的时候,要么width为零,要么height为零,这种情况下数值越大,权重越大,官方文档是这么写的

发自我的 iPhone

在 2013-6-14,14:23,"Kris.lee" [email protected] 写道:

'''
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:id="@+id/textView1"
android:layout_weight="0.5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Weight 0.5"
android:background="#ff0" />

<TextView
    android:id="@+id/textView2"
    android:layout_weight="1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Weight 1"
    android:background="#f00"/>

'''


Reply to this email directly or view it on GitHub.

from google_android_book_v2.

krislq avatar krislq commented on June 12, 2024

@snowxwyo 你是相信眼见为实还是文档 ? 或者你把你的实际效果帖出来征服我

from google_android_book_v2.

vincent4j avatar vincent4j commented on June 12, 2024

他手机,可能不方便吧。再有文档,贴具体的链接。

from google_android_book_v2.

futurexiong avatar futurexiong commented on June 12, 2024

哈哈,weight这个属性比较复杂,两种结果都有可能的,要看布局如何去写。

from google_android_book_v2.

krislq avatar krislq commented on June 12, 2024

@futurexiong 哦?哪种情况下可以实现weight值越大占的比重越大?

from google_android_book_v2.

futurexiong avatar futurexiong commented on June 12, 2024

最简单的就是width或者height为0嘛

futurexiong

在 2013年6月14日,15:03,"Kris.lee" [email protected] 写道:

@futurexiong 哦?哪种情况下可以实现weight值越大占的比重越大?


Reply to this email directly or view it on GitHub.

from google_android_book_v2.

snowxwyo avatar snowxwyo commented on June 12, 2024

width或height其中一项设置为0dp的时候,weight越大,权重越大,我试过了,但现在没网,只能用手机,发不了截图

发自我的 iPhone

在 2013-6-14,15:03,"Kris.lee" [email protected] 写道:

@futurexiong 哦?哪种情况下可以实现weight值越大占的比重越大?


Reply to this email directly or view it on GitHub.

from google_android_book_v2.

krislq avatar krislq commented on June 12, 2024

@snowxwyo @futurexiong @vincent4j
总结下: (前提是horizontal->width ; vertical ->height)
1.width或height其中一项设置为0dp的时候,weight越大,权重越大
2.width或height其中一项设置为match_parent的时候,weight越大,权重越小
3.width或height其中一项设置为wrap_content的时候,自动适应

from google_android_book_v2.

vincent4j avatar vincent4j commented on June 12, 2024

已经摘录进 wiki,可以 close 掉。

from google_android_book_v2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.