Skip to content

Commit d65d714

Browse files
committed
Create CustomFragment1
1 parent 0a13321 commit d65d714

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright 2018 JessYan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package me.jessyan.autosize.demo;
17+
18+
import android.os.Bundle;
19+
import android.support.annotation.NonNull;
20+
import android.support.annotation.Nullable;
21+
import android.support.v4.app.Fragment;
22+
import android.view.Gravity;
23+
import android.view.LayoutInflater;
24+
import android.view.View;
25+
import android.view.ViewGroup;
26+
import android.widget.TextView;
27+
28+
import me.jessyan.autosize.internal.CustomAdapt;
29+
import me.jessyan.autosize.utils.AutoSizeUtils;
30+
31+
/**
32+
* ================================================
33+
* Created by JessYan on 2018/8/25 14:06
34+
* <a href="mailto:[email protected]">Contact me</a>
35+
* <a href="https://github.com/JessYanCoding">Follow me</a>
36+
* ================================================
37+
*/
38+
public class CustomFragment1 extends Fragment implements CustomAdapt {
39+
40+
@Nullable
41+
@Override
42+
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
43+
return createTextView(inflater, "Fragment-1\nView width = 360dp\nTotal width = 1080dp", 0xffff0000);
44+
}
45+
46+
@Override
47+
public boolean isBaseOnWidth() {
48+
return true;
49+
}
50+
51+
@Override
52+
public float getSizeInDp() {
53+
return 1080;
54+
}
55+
56+
public static View createTextView(LayoutInflater inflater, String content, int backgroundColor) {
57+
TextView view = new TextView(inflater.getContext());
58+
ViewGroup.LayoutParams layoutParams =
59+
new ViewGroup.LayoutParams((AutoSizeUtils.dp2px(inflater.getContext(), 360)),
60+
ViewGroup.LayoutParams.MATCH_PARENT);
61+
view.setLayoutParams(layoutParams);
62+
view.setText(content);
63+
view.setTextColor(0xffffffff);
64+
view.setGravity(Gravity.CENTER);
65+
view.setTextSize(30);
66+
view.setBackgroundColor(backgroundColor);
67+
return view;
68+
}
69+
}

0 commit comments

Comments
 (0)