ImageView แบบวงกลมที่รวดเร็วเหมาะสำหรับภาพโปรไฟล์ สิ่งนี้อิงจาก RoundedImageView จาก Vince Mi ซึ่งอิงตามเทคนิคที่แนะนำโดย Romain Guy
มันใช้ BitmapShader และ ไม่ :
เนื่องจากนี่เป็นเพียง ImageView แบบกำหนดเอง และไม่ใช่ Drawable แบบกำหนดเองหรือทั้งสองอย่างรวมกัน จึงสามารถใช้กับ Drawable ได้ทุกประเภท เช่น PicassoDrawable จาก Picasso หรือ Drawable ที่ไม่ได้มาตรฐานอื่นๆ (ต้องมีการทดสอบบ้าง)
dependencies {
...
implementation 'de.hdodenhof:circleimageview:3.1.0'
}
< de .hdodenhof.circleimageview.CircleImageView
xmlns : app = " http://schemas.android.com/apk/res-auto "
android : id = " @+id/profile_image "
android : layout_width = " 96dp "
android : layout_height = " 96dp "
android : src = " @drawable/profile "
app : civ_border_width = " 2dp "
app : civ_border_color = " #FF000000 " />
adjustViewBounds
เนื่องจากต้องใช้ ScaleType ที่ไม่รองรับnoFade()
สำหรับ Glide ให้ใช้ dontAnimate()
หากคุณต้องการเก็บแอนิเมชั่น fadeIn ไว้ คุณต้องดึงรูปภาพมาไว้ใน Target
และใช้แอนิเมชั่นแบบกำหนดเองด้วยตนเองเมื่อได้รับ Bitmap
TransitionDrawable
กับ CircleImageView
ทำงานไม่ถูกต้องและทำให้ภาพที่เลอะเทอะ ฉันจะใช้ VectorDrawable
กับ CircleImageView
ได้อย่างไร
คำตอบสั้น ๆ : คุณไม่ควร การใช้ VectorDrawable
กับ CircleImageView
นั้นไม่มีประสิทธิภาพมากนัก คุณควรแก้ไขเวกเตอร์ของคุณให้เป็นรูปวงกลมและใช้กับ ImageView ปกติแทน
เหตุใด CircleImageView
จึงไม่ขยาย AppCompatImageView
การขยาย AppCompatImageView
จะต้องเพิ่มการพึ่งพารันไทม์สำหรับไลบรารีการสนับสนุนโดยไม่มีประโยชน์ที่แท้จริง
ฉันจะเพิ่มตัวเลือก (เช่น เอฟเฟกต์ระลอกคลื่น) ที่ผูกไว้กับวงกลมได้อย่างไร
ขณะนี้ยังไม่มีการสนับสนุนโดยตรงสำหรับตัวเลือกที่ถูกผูกไว้แบบวงกลม แต่คุณสามารถทำตามขั้นตอนเหล่านี้เพื่อนำไปใช้ด้วยตนเอง
ฉันจะเพิ่มช่องว่างระหว่างรูปภาพและเส้นขอบได้อย่างไร
การเพิ่มช่องว่างยังไม่ได้รับการสนับสนุนโดยตรงแต่มีวิธีแก้ไขชั่วคราว
Copyright 2014 - 2020 Henning Dodenhof
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.