java – 将相对布局中的宽度和高度设置为百分比
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 将相对布局中的宽度和高度设置为百分比,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3071字,纯文字阅读大概需要5分钟。
内容图文
![java – 将相对布局中的宽度和高度设置为百分比](/upload/InfoBanner/zyjiaocheng/809/d4413c211ab74d78b8defb9ff40be4a6.jpg)
我想这样:一个由2个箭头覆盖的ViewPager
我得到了我想要的代码.但是,我得到了lint的这些警告:
>这种布局没用(对于虚拟布局)
>嵌套权重对性能不利.
我想知道是否有更好的方法来获得我想要的UI.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.v4.view.ViewPager
android:id="@+id/dialog_instruction_pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</android.support.v4.view.ViewPager>
<!-- this LinearLayout overlays the ViewPager -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<!-- This is just the container for the left and right arrows , it is allocated with only 20% of screen height-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".2"
android:orientation="horizontal" >
<!-- I want to align this to the left and set width only 5% of the parent -->
<ImageButton
android:id="@+id/instruction_dialog_left_arrow"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".05"
android:background="?android:attr/selectableItemBackground"
android:scaleType="fitCenter"
android:src="@drawable/arrow_left_grey" />
<!-- This is the dummy layout, standing in the middle of 2 arrows so they can be align to the left and right of the parent -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".8" >
</LinearLayout>
<!-- I want to align this to the right and set width only 5% of the parent-->
<ImageButton
android:id="@+id/instruction_dialog_right_arrow"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".05"
android:background="?android:attr/selectableItemBackground"
android:scaleType="fitCenter"
android:src="@drawable/arrow_right_grey" />
</LinearLayout>
</LinearLayout>
P.S:是否有任何布局允许对齐左边,右边,底部(如RelativeLayout),还允许设置宽度,高度为百分比(如LinearLayout中的“weight”属性)?
谢谢 !
解决方法:
Try the below code and see whether it works,
This code will get the layout what you have attached
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/dialog_instruction_pager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/theme_blue" >
</android.support.v4.view.ViewPager>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:background="@drawable/ic_launcher" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:background="@drawable/ic_launcher" />
</RelativeLayout>
内容总结
以上是互联网集市为您收集整理的java – 将相对布局中的宽度和高度设置为百分比全部内容,希望文章能够帮你解决java – 将相对布局中的宽度和高度设置为百分比所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。