我想根据一些事件在 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/