gpt4 book ai didi

java - 在 Java 中设置 PercentRelativeLayout 百分比

转载 作者:搜寻专家 更新时间:2023-11-01 07:50:07 24 4
gpt4 key购买 nike

我想根据某些事件在 Java 中动态更改 PercentRelativeLayout 中项目的宽度百分比,我找到了这个,但我找不到放置百分比的位置:

mLinerLayout.setLayoutParams(new PercentRelativeLayout.LayoutParams());

我的 xml 看起来像这样:

<android.support.percent.PercentRelativeLayout
android:id="@+id/ad_prl_tags"
android:layout_width="match_parent"
android:layout_height="48dp">

<android.support.v7.widget.RecyclerView
android:id="@+id/ad_rv_tags"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
app:layout_widthPercent="70%" />

<!--Add Tags Button-->

<LinearLayout
android:id="@+id/ad_ll_add_tags_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@id/ad_rv_tags">

<ImageView
android:id="@+id/itd_animatable_plus_iv"
android:layout_width="wrap_content"
android:layout_height="match_parent" />

<EditText
android:id="@+id/ad_et_add_tags_and_info"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.percent.PercentRelativeLayout>

我想在 Java 中将 LinearLayout 的宽度百分比设置为 70%,将 RecyclerView 的宽度设置为 30%。

最佳答案

您可以通过此方法实用地使用它:

public static void setWidthPercent(View view, float width) {
PercentLayoutHelper.PercentLayoutParams params =(PercentLayoutHelper.PercentLayoutParams) view.getLayoutParams();
PercentLayoutHelper.PercentLayoutInfo info = params.getPercentLayoutInfo();
info.widthPercent = width;
}

关于java - 在 Java 中设置 PercentRelativeLayout 百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35914830/

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