AndroidAutoLayout
[DEPRECATED]Android???????????????????????????
??????????????????????????????????????????????????????
???? ? ????? ????
???
??????????????????????
so,?????
??????????????????????????px???px:???px???Google??????px????????????
ok????????????????????????
???768 * 1280 ; ???1080 * 1920
?????????????????????????????????
- ??????????????????????dp
- ??????????????dimens
- ??????????????????????????
- ??????UI MM??????dp?
???????????????px??????????
????????????Item????????????????????FrameLayout????View????marginLeft,marginTop????????????????
??
- Android Studio
? autolayout??
dependencies {
compile project(':autolayout')
}
?????
dependencies {
compile 'com.zhy:autolayout:1.4.5'
}
- Eclipse
????As???????????????????????
??
????
??????AndroidManifest????? ???
????
<meta-data android:name="design_width" android:value="768"> </meta-data> <meta-data android:name="design_height" android:value="1280"> </meta-data>
????
???Activity??? AutoLayoutActivity
.
???????????????????????????????sample?
????
???????? AutoLayoutActivity
?????????????
- LinearLayout -> AutoLinearLayout
- RelativeLayout -> AutoRelativeLayout
- FrameLayout -> AutoFrameLayout
??????????
??????
- layout_width
- layout_height
- layout_margin(left,top,right,bottom)
- pading(left,top,right,bottom)
- textSize
- maxWidth, minWidth, maxHeight, minHeight
??
??????????????????????????????????????????????????????
???Application?onCreate???????:
public class UseDeviceSizeApplication extends Application {
@Override
public void onCreate()
{
super.onCreate();
AutoLayoutConifg.getInstance().useDeviceSize();
}
}
??
???????????????????????????????????????????????????????????????????PreView???????
????????????????? 768 * 1280
?????PreView??????????????????
???????? ?????
????
???????
- ??UI??????????????????????????????????????
- ???PreView????????????????????????????????????
??
?????????FrameLayout?LinearLayout?RelativeLayout?????? CardView
?????????????"px"??????????????????????????? issue#21?
package com.zhy.sample.view; import android.content.Context; import android.support.v7.widget.CardView; import android.util.AttributeSet; import com.zhy.autolayout.AutoFrameLayout; import com.zhy.autolayout.utils.AutoLayoutHelper; /** * Created by zhy on 15/12/8. */ public class AutoCardView extends CardView {
private final AutoLayoutHelper mHelper = new AutoLayoutHelper(this);
public AutoCardView(Context context)
{
super(context);
}
public AutoCardView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public AutoCardView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
}
@Override
public AutoFrameLayout.LayoutParams generateLayoutParams(AttributeSet attrs)
{
return new AutoFrameLayout.LayoutParams(getContext(), attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
if (!isInEditMode())
{
mHelper.adjustChildren();
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
????
ListView?RecyclerView??Item???
sample???ListView?RecyclerView???????sample
- ??ListView
??ListView?????item???????“px”??????????????AutoXXXLayout???ListView???????????????????
@Override public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null)
{
holder = new ViewHolder();
convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item, parent, false);
convertView.setTag(holder);
//??listview????????????item?????
AutoUtils.autoSize(convertView);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
return convertView;
}
?? AutoUtils.autoSize(convertView);
??????????demo????????
- ??RecyclerView
public ViewHolder(View itemView) {
super(itemView);
AutoUtils.autoSize(itemView);
}
//... @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View convertView = LayoutInflater.from(mContext).inflate(R.layout.recyclerview_item, parent, false);
return new ViewHolder(convertView);
}
????? LayoutInflater.from(mContext).inflate
??????????
??????????????
?????????????????1px??????????????????????????????
app:layout_auto_basewidth="height"
???height????????????
app:layout_auto_baseheight="width"
???width????????????
???????????????
app:layout_auto_basewidth="height|padding"
?|?????gravity????????
- width,height
- margin,marginLeft,marginTop,marginRight,marginBottom
- padding,paddingLeft,paddingTop,paddingRight,paddingBottom
- textSize.
TextView?????
??????????????????????textSize="20px"????TextView??????????20px?????????????????????????????????text???margin?????????????????????????????????marginBottom?
????
###(1)????? org/gradle/api/publication/maven/internal/DefaultMavenFactory
????????? compile 'com.zhy:autolayout:x.x.x'
?????????????module??????issue #74
###(2)RadioGroup,Toolbar??????View??????
????????????????????????????????????????????? ?? autolayout-widget, ?????????????????????????????????????????????PR?????????????? autolayout-widget
??????ps:??????copy?????????? autolayout-widget
???????????????? ????????
###(3)java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
?????????AutoLayoutActivity????AppCompatActivity????????? Theme.AppCompat?theme?
?????????FragmentActivity????????AppCompatActivity? ??????????? MyAutoLayoutActivity extends ??????Activity??
??? MyAutoLayoutActivity extends FragmentActivity
???????AutoLayoutActivity???? ??????????????? MyAutoLayoutActivity
????
ps?????????SDK???? AppCompatActivity
.
????
?????
- hongyangAndroid
- ?????
?????