相关疑难解决方法(0)

Android:如何以编程方式设置布局的大小

作为Android应用程序的一部分,我正在构建一个按钮集.这些按钮是嵌套的LinearLayouts集的一部分.使用权重我根据包含父LinearLayout的大小自动调整自身大小.该想法是,基于屏幕的像素数和密度,将包含布局的大小设置为多个像素; 并根据该更改让按钮设置自行调整大小.

那么问题是:如何调整布局大小.

我已经尝试了几种建议的技术,没有一种能够接近工作.以下是构建按钮集的XML的子集:

    <LinearLayout android:layout_height="104pt" android:id="@+id/numberPadLayout" android:orientation="horizontal" android:layout_width="104pt"
    android:background="#a0a0a0"
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true"
>

    <LinearLayout android:layout_weight="2" android:layout_height="fill_parent" android:id="@+id/linearLayout1" android:orientation="vertical" android:layout_width="wrap_content">
        <Button android:text="1" android:id="@+id/button1" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="4" android:id="@+id/button4" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="7" android:id="@+id/button7" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="-" android:id="@+id/buttonDash" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
    </LinearLayout>
    <LinearLayout android:layout_weight="2" android:layout_height="fill_parent" android:id="@+id/linearLayout2" android:orientation="vertical" android:layout_width="wrap_content">
        <Button android:text="2" android:id="@+id/button2" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="5" android:id="@+id/button5" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="8" android:id="@+id/button8" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
        <Button android:text="0" android:id="@+id/button0" android:layout_weight="2" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
    </LinearLayout>

    <LinearLayout android:layout_weight="2" android:layout_height="fill_parent" android:id="@+id/linearLayout3" android:orientation="vertical" …
Run Code Online (Sandbox Code Playgroud)

layout android resize android-linearlayout

133
推荐指数
3
解决办法
25万
查看次数

Facebook Fresco使用wrap_content

我有一堆drawables,我想用壁画加载,我想使用wrap_content这些图像的大小,我怎么能在壁画的xml中做到这一点?或者,如果不可能使用xml,您如何在代码中执行此操作?

<com.facebook.drawee.view.SimpleDraweeView
          android:id="@+id/myImage"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          fresco:placeholderImage="@mipmap/myImage"/>
Run Code Online (Sandbox Code Playgroud)

除非我设置固定大小,否则上述代码无效.

android facebook fresco

15
推荐指数
2
解决办法
8730
查看次数