Reprint: Http://www.jianshu.com/p/117d065685be
1, the use of progress bar ProgressBar:
比如在不需要自定义的情况下,显示响应的比例(eg:20/100),则可以使用clip标签对drawable进行裁剪,在做进度条时很有用。通过设置level值控制裁剪多少,level取值范围为0~10000,默认为0,表示完全裁剪,图片将不可见;10000则完全不裁剪,可见完整图片。看看clip标签可以设置的属性:
android:drawable Specifies the drawable resource, and if you do not set the property, you can also define a sub-label of the drawable type;
Android:cliporientation set the orientation of the crop to one of the following two values:
Horizontal in the horizontal direction of cutting, bar-shaped progress bar is the horizontal direction of cutting;
Vertical in the vertical direction of the cutting;
Android:gravity set the clipping position, the values are as follows, multiple values are used | Separated
Top picture is placed at the top of the container without changing the image size. When the clipping direction is vertical, the bottom of the image will be cut off;
The bottom picture is placed at the bottom of the container without changing the image size. When the clipping direction is vertical, the top of the picture is cut off;
The left picture is placed on the container to the ieft, without changing the image size, default value. When the clipping direction is horizontal, the right part of the picture will be cut off;
The right picture is placed on the left side of the container without changing the image size. When the clipping direction is horizontal, the left part of the picture will be cut off;
The center picture is placed in the central position of the container, both horizontally and vertically, without changing the image size. When the clipping direction is horizontal, the left and right parts of the picture are cut off, and when the clipping direction is vertical, the upper and lower parts of the picture are cropped;
Fill stretches the entire picture to fill the container's entire height and width. This time the picture will not be cropped, unless level is set to 0, when the picture is not visible;
The center_vertical picture is placed in the central position of the container vertically, without changing the image size. Cropping is the same as the center;
The center_horizontal picture is placed in the central position of the container horizontally, without changing the image size. Cropping is the same as the center;
Fill_vertical stretches the picture vertically to fill the container's entire height. When the clipping direction is vertical, the picture is not cropped, unless level is set to 0, when the picture is not visible;
Fill_horizontal stretches the picture horizontally to fill the container's entire width. When the clipping direction is horizontal, the picture is not cropped, unless level is set to 0, when the picture is not visible;
Clip_vertical additional options, crop the gravity setting based on the vertical orientation, crop the bottom when the top is set, crop the top when setting the bottom, and crop the top and bottom at the same time;
Clip_horizontal additional options, crop the gravity settings based on the horizontal direction, set left to crop to the right, and crop to the other when set to, others will crop both sides at the same time.
2. Use the glide picture to load the hole that the frame encounters:
* Glide加载图片变绿
, the alpha channel is missing, causing the image to become green.
* Solution
Glide.setup (new Glidebuilder (context). Setdecodeformat (decodeformat.prefer_argb_8888));
* Glide在弱网状态下加载大图片,失败几率很大。 * 解决方案,配置自己的网络栈, * 前提:我用的是Retrofit2,其内部使用的是OkHttp3. * 配置
Compile ' com.github.bumptech.glide:okhttp3-integration:[email protected]'
* Custom Glidemodule
public class Myglidemodule implements Glidemodule {
@Override
public void registercomponents (context context, Glide Glide) {
Set up long-time read and wire break re-connect
Okhttpclient client = new Okhttpclient.builder (). ConnectTimeout (Timeunit.minutes). ReadTimeout (10, timeunit.minutes). Retryonconnectionfailure (True). Build ();
Glide.register (Glideurl.class, Inputstream.class, new Okhttpurlloader.factory (client));
}
@Override
public void Applyoptions (context context, Glidebuilder Builder) {
Prevents the image from getting green, in the case of an alpha channel
Builder.setdecodeformat (decodeformat.prefer_argb_8888);
}
}
* Manifest's application tag configuration
<application>
<meta-data
Android:name= "Com.example.admin.quwang.http.MyGlideModule"
Android:value= "Glidemodule" >
</application>
* Can solve the picture loading problem in the weak network state
* Glide的OOM * ImageView设置的ScaleType是fitxy,Glide会默认按照图片实际大小加载。而其他的模式按照的ImageView的大小。 * 如果非要设置fitxy,那么使Glide.with(context).load().centerCrop().into();或者使用 Glide.with(context).load().fitCenter().into()* Glide 和dataBinding共同使用的时候,根节点不能是ImageView。 * 原因:Glide加载图片时候为了防止图片错位会给ImageView设置Tag,而dataBinding的原理也是给View设置tag。这样就会导致类型转换异常 * 解决方案:给ImageView嵌套一层父亲容器。
3, Android splash screen processing:
To jump from one application or activity to another, or another activity, if you want to implement a splash screen or a blank screen, you can add properties to the activity in the manifest file:
style = "@android: Style/theme.nodisplay", so you can avoid it altogether.
4. Click Conflict in ListView or GridView control in Android
The situation is as follows: A CheckBox control is added to the image, which conflicts with the checkbox's listener event when the image is clicked, causing the click image to be unresponsive or not to jump;
That is: The OnClick event of the GridView or the Onitemclick event conflicts with the listener event of the CheckBox control;
Workaround:
Add the following three sentences to the CheckBox control in the layout:
Android:clickable= "true"
Android:focusable= "false"
Android:focusableintouchmode= "false"
5, WebView LoadData () Chinese garbled
Generally used LoadData (data, "text/html", "Utf-8") will lead to garbled;
Workaround: LoadData (data, "text/html", "Utf-8", null);
The reason is: You can use LoadData, refresh is only taken from the cache, but in more than 4.0, if the API is written in LoadData (data, "UTF-8", null), the time will be garbled, if written loaddata (data, "text/html ; Charset=utf-8 ", null); LoadData The final mechanism is to put the incoming three parameters together, and then Loadurl operation, the parameter is data," text/html; Charset=utf-8 ", null these three are assembled, joined text/html; Charset=utf-8 is equivalent to restricting the character of the page
6, Httpmime-4.1.3.jar and Fastjson-1.2.8.jar conflict
In the Build.gradle file under app, add:
packagingoptions {
Exclude (' Meta-inf/notice.txt ')
}
7, photographic access to data problems
When the system camera is called, when the picture is taken, the vertical screen is returned, and the OnCreate method is called, in the activity manifest file of the camera that calls the system, add android:configchanges= "orientaion| Keyboardhidden ", so the picture will be a vertical screen, you can get the data.
8, about the picture caused by the oom problem
In the folder drawable can not put more than 1M picture, otherwise will report memory overflow (OOM) exception, you can choose to put in drawable-hdpi, or even larger resolution of the picture folder.
9, about the Android Studio import Project garbled problem
The code in Chinese display normal, the real machine after the Chinese display garbled, the solution:
Add a sentence to the Build.gradle
Android {
compileoptions.encoding = "GBK"
}
14. The pits that have been trampled in Android (turn)