android:layout_with="",GitHub - mapleqin/Android-RatioLayout: This is a specified proportion to the ...

Android-RatioLayout 68747470733a2f2f7472617669732d63692e6f72672f616d70686961726175732f416e64726f69642d526174696f4c61796f75742e73766768747470733a2f2f6170692e62696e747261792e636f6d2f7061636b616765732f736f756c776f6c662f6d6176656e2f726174696f6c61796f75742f696d616765732f646f776e6c6f61642e737667

This is a specified proportion to the size of the Layout or View support library, with which you can easily set a fixed ratio of the size of the Layout or View, internal adaptive size calculation, completely abandon the code to calculate the size! If you have any questions in the course or suggestions, please send an e-mail to the following e-mail, thank you!

For more information please see the website

Screenshots

e1c82739a8f341115103e0f584c9aee3.png

2da92228dc6aec175d9120a4126dfbf6.png

Android-RatioLayout with xml code

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

app:datumRatio="datumWidth"

app:widthRatio="16.0"

app:heightRatio="9.0"

android:layout_height="wrap_content">

android:id="@+id/image2"

android:layout_width="match_parent"

android:layout_height="match_parent"

app:datumRatio="datumWidth"

app:widthRatio="16.0"

app:heightRatio="7.0"

android:scaleType="centerCrop"/>

android:layout_width="match_parent"

android:layout_height="match_parent"

android:textSize="25sp"

android:textStyle="bold"

android:gravity="center"

app:datumRatio="datumWidth"

app:widthRatio="16.0"

android:background="@color/sample_text"

app:heightRatio="7.0"

android:text="RatioImageView/RatioTextView:16*7"

android:textColor="@android:color/white"/>

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="8dp"

android:orientation="horizontal">

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@color/sample_primary"

android:gravity="center"

android:text="Square"

android:textColor="@android:color/white"

android:textSize="20sp"

android:textStyle="bold"

app:layoutSquare="true"/>

android:layout_width="15dp"

android:layout_height="wrap_content"

app:heightRatio="1"

app:widthRatio="1"/>

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:background="@color/sample_primary"

android:gravity="center"

android:text="AspectRatio:1.0"

android:textColor="@android:color/white"

android:textSize="20sp"

android:textStyle="bold"

app:layoutAspectRatio="1"/>

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

app:datumRatio="datumWidth"

app:widthRatio="15.0"

app:layout_marginTop="8dp"

app:heightRatio="10.0"

app:layout_height="wrap_content"/>

Android-RatioLayout with java code

RatioFrameLayout ratioFrameLayout = new RatioFrameLayout(context);

ratioFrameLayout.setRatio(datumRatio,widthRatio,heightRatio);

ratioFrameLayout.setSquare(square);

ratioFrameLayout.setAspectRatio(aspectRatio);

Attr params info

attrName

Explanation

datumRatio

This parameter indicates the ratio is calculated based on Width Or Height! Default auto

widthRatio

This parameter indicates the proportion of the size Width

heightRatio

This parameter indicates the proportion of the size Height

layoutSquare

This parameter indicates the proportion of the square

layoutAspectRatio

This parameter indicates the proportion of the (width / height)

Implementing View!

RatioAbsoluteLayout

RatioLinearLayout

RatioButton

RatioCheckBox

RatioCheckedTextView

RatioEditText

RatioFrameLayout

RatioGridLayout

RatioImageButton

RatioImageView

RatioProgressBar

RatioRadioButton

RatioRadioGroup

RatioRelativeLayout

RatioSpace

RatioTableLayout

RatioTextView

RatioGridView

RatioListView

RatioRecyclerView

RatioCardView

Custom

public class RatioFrameLayout extends FrameLayout implements RatioMeasureDelegate {

private RatioLayoutDelegate mRatioLayoutDelegate;

public RatioFrameLayout(Context context) {

super(context);

}

public RatioFrameLayout(Context context, AttributeSet attrs) {

super(context, attrs);

mRatioLayoutDelegate = RatioLayoutDelegate.obtain(this, attrs);

}

public RatioFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

mRatioLayoutDelegate = RatioLayoutDelegate.obtain(this, attrs, defStyleAttr);

}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)

public RatioFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {

super(context, attrs, defStyleAttr, defStyleRes);

mRatioLayoutDelegate = RatioLayoutDelegate.obtain(this, attrs, defStyleAttr, defStyleRes);

}

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

if (mRatioLayoutDelegate != null) {

mRatioLayoutDelegate.update(widthMeasureSpec, heightMeasureSpec);

widthMeasureSpec = mRatioLayoutDelegate.getWidthMeasureSpec();

heightMeasureSpec = mRatioLayoutDelegate.getHeightMeasureSpec();

}

super.onMeasure(widthMeasureSpec, heightMeasureSpec);

}

@Override

public void setRatio(RatioDatumMode mode, float datumWidth, float datumHeight) {

if (mRatioLayoutDelegate != null) {

mRatioLayoutDelegate.setRatio(mode, datumWidth, datumHeight);

}

}

@Override

public void setSquare(boolean square) {

if (mRatioLayoutDelegate != null) {

mRatioLayoutDelegate.setSquare(square);

}

}

@Override

public void setAspectRatio(float aspectRatio) {

if (mRatioLayoutDelegate != null) {

mRatioLayoutDelegate.setAspectRatio(aspectRatio);

}

}

}

Maven

net.soulwolf.widget

ratiolayout

2.1.0

pom

Gradle

allprojects {

repositories {

jcenter()

}

}

compile 'net.soulwolf.widget:ratiolayout:2.1.0'

Developed by

License

Copyright 2015 The Android Open Source Project for Android-RatioLayout

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

下面是Android Studio失物招领模块Xml文件的实现代码,请修改代码实现下拉以及图片上传功 <TextView android:id="@+id/shiwuzhaolingzi" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="请选择是失物还是招领" /> <Spinner android:id="@+id/spinner_lost_found" android:layout_width="match_parent" android:layout_height="wrap_content" android:entries="@array/lost_found_array" /> <TextView android:id="@+id/text_item_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="物品名称" /> <EditText android:id="@+id/edit_item_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="text" /> <TextView android:id="@+id/text_item_desc" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="物品描述" /> <EditText android:id="@+id/edit_item_desc" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="text" /> <TextView android:id="@+id/text_item_time" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="时间" /> <EditText android:id="@+id/edit_item_time" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="text" /> <TextView android:id="@+id/text_item_location" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="地点" /> <EditText android:id="@+id/edit_item_location" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="text" /> <Button android:id="@+id/button_upload_image" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="上传图片" /> <TextView android:id="@+id/text_image_path" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="图片路径:" /> <Button android:id="@+id/button_submit" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="提交" /> </LinearLayout>
05-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值