gpt4 book ai didi

android - 如何以编程方式将 ImageView 对齐到 LinearLayout 的右侧 android

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:07:20 25 4
gpt4 key购买 nike

我想以编程方式将 ImageView 对齐到 LinearLayout 的右侧。我该怎么做。

最佳答案

你不知道。这不是线性布局的作用。使用RelativeLayout相反。

XML

<RelativeLayout android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!"
android:layout_alignParentRight="true"/>
</RelativeLayout>

以编程方式

public void makeView(Context context) {
RelativeLayout rl = new RelativeLayout(context);
TextView tv = new TextView(context);
tv.setText("Hello, World");

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams
(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

rl.addView(tv, lp);
}

关于android - 如何以编程方式将 ImageView 对齐到 LinearLayout 的右侧 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8763954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com