Cường Ngô
5 questions
0 answers
Avatar
0
Cường Ngô Beginner
Cường Ngô Beginner
Responsive trong kotlin
<img src="/api/v1/media/0e988550c8c46e11c3abc75c07f37dd1a21afcaf5cd4ac55afb6025a9c71ae37.jpg" alt="Messenger_creation_d78ec69d-da4d-43f1-ae4e-7ec6f7d8893b.jpeg"> <img src="/api/v1/media/4e60eafd8f5410975528dd1e9b5cbadcbcb00f0cfcb4ad778dd3379818c646ec.jpg" alt="Messenger_creation_3c513bf1-a2d1-4c25-a6b7-4e8006e3b899.jpeg"> <p> Mọi người cho e hỏi e đã chỉnh sdp và ddp rồi. E test trên mọi máy thì nó hiển thị ok, nhưng khi mà e tăng font size trên máy thì nó sẽ bị chèn chữ, có cách nào khắc phục không ạ. E cảm ơn. </p>
Answer
Avatar
0
Cường Ngô Beginner
Cường Ngô Beginner
Tạo mũi tên giữa hai views
Giúp em cái này với ạ, e muốn vẽ mũi tên nẵm chính giữa 2 views, nhưng mà nó cứ bị lệch, code của e đây ạ.<div class="markdown-block position-relative overflow-auto source-"> <pre> <span class="pl-k">val</span> mImageView = findViewById&lt;ImageView&gt;(R.id.image_view_1) <span class="pl-k">val</span> mButton = findViewById&lt;Button&gt;(R.id.button_1) <span class="pl-k">val</span> tv1 = findViewById&lt;View&gt;(R.id.textView) <span class="pl-k">val</span> tv2 = findViewById&lt;View&gt;(R.id.textView2) <span class="pl-k">val</span> currentDisplay = windowManager.currentWindowMetrics <span class="pl-k">val</span> dw = currentDisplay.bounds.width() <span class="pl-k">val</span> dh = currentDisplay.bounds.height() <span class="pl-k">val</span> mBitmap = Bitmap.createBitmap(dw, dh, Bitmap.Config.ARGB_8888) <span class="pl-k">val</span> mCanvas = Canvas(mBitmap) mImageView.setImageBitmap(mBitmap) mButton.setOnClickListener { <span class="pl-k">val</span> mPaint = Paint() mPaint.color = Color.GREEN mPaint.style = Paint.Style.STROKE mPaint.strokeWidth = 10F mPaint.isAntiAlias = <span class="pl-k">true</span> <span class="pl-k">val</span> mStartX = tv1.bottom.toFloat() <span class="pl-k">val</span> mStartY = tv1.left.toFloat() <span class="pl-k">val</span> mStopX = tv2.top.toFloat() <span class="pl-k">val</span> mStopY = tv2.right.toFloat() mCanvas.drawLine(mStartX, mStartY, mStopX, mStopY, mPaint) mImageView.setImageBitmap(mBitmap) } </pre> </div>e muốn kết quả như vầy ạ. <img src="/api/v1/media/5ff9a25e6f01dbef961b858c07ddd60b17d0ff2c8e15ebb55a4163c84ef248ee.png" alt="s.png"> <p> còn đây là hình code chạy </p> <img src="/api/v1/media/311c305f3610af36b9809de3dbc49097631e0336ccbe8760838671e10c21cc86.jpg" alt="z4765858565121_90a7d7791567c04d5e6334f2ef6f8d54.jpg">
Answer
Avatar
1
Cường Ngô Beginner
Cường Ngô Beginner
Arraylist trong Kotlin
E có một arraylist với nhiều giá trị thứ [0] trùng nhau, giờ e muốn bỏ hết những giá trị thứ [0] trùng nhau đó nhưng để lại giá trị thứ [1] lớn nhất của giá trị thứ [0] đó thì như thế nào ạ. <p> </p> <p> Theo như trong hình này thì e chỉ muốn để lại [a,3][b,3][c,3] thôi, em cảm ơn.<img class="alignnone size-full wp-image-7694" src="https://stackask.com/wp-content/uploads/2022/10/ssssss.jpg" alt="" /> </p>
Answer
Avatar
0
Cường Ngô Beginner
Cường Ngô Beginner
Refresh gallery
Mọi người cho e hỏi vấn đề này với, e muốn chụp ảnh cái textview lại, nhưng khi code chụp xong rồi thì vào thu mục ảnh lại không thấy hiện ảnh lên ạ. Code: <p> </p> <pre> import android.content.ContentValues import android.content.Context import android.content.Intent import android.graphics.Bitmap import android.net.Uri import android.os.Build import android.os.Environment import android.provider.MediaStore import android.text.format.DateFormat import android.widget.Toast import java.io.File import java.io.FileOutputStream import java.io.OutputStream import java.util.* data class TakeSS(val bitmap: Bitmap, val context: Context, val img_name: String) { fun savescrolltoGallery() { val date = Date() val now = DateFormat.format("yyyyMMddhhmmss", date) val fos: OutputStream try { if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.Q) { val resolver = context.contentResolver val contentValue = ContentValues() contentValue.put(MediaStore.MediaColumns.DISPLAY_NAME, "$img_name.jpg") contentValue.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpg") contentValue.put( MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_PICTURES + File.separator + "Huyền Học" ) val imageUri = resolver?.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValue) fos = resolver?.openOutputStream(Objects.requireNonNull(imageUri)!!)!! bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos) Toast.makeText(context, "$img_name.jpg", Toast.LENGTH_LONG).show() } else{ TakeSS(bitmap) } } catch (e: Exception) { Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show() } } fun TakeSS(contrain_content: Bitmap) { val date = Date() val now = DateFormat.format("yyyyMMddhhmmss", date) try { // image naming and path to include sd card appending name you choose for file val mPath = Environment.getExternalStorageDirectory() .toString() + "/Huyền Học/$img_name.jpg" val imageFile = File(mPath) imageFile.parentFile!!.mkdirs() val outputStream = FileOutputStream(imageFile) val quality = 100 contrain_content.compress( Bitmap.CompressFormat.JPEG, quality, outputStream ) outputStream.flush() outputStream.close() val uri = Uri.fromFile(imageFile) Toast.makeText(context, img_name, Toast.LENGTH_SHORT).show() } catch (e: Throwable) { // Several error may come out with file handling or DOM e.printStackTrace() } } } </pre>
Answer
Avatar
0
Cường Ngô Beginner
Cường Ngô Beginner
Lỗi chèn chữ
<img class="alignnone size-full wp-image-5490" src="https://stackask.com/wp-content/uploads/2022/04/1443c6952c02e25cbb13.jpg" alt="" /> <img class="alignnone size-full-size wp-image-5491" src="https://stackask.com/wp-content/uploads/2022/04/466a31a7db30156e4c21.jpg" alt="" /> <p> </p> <p> cho em hỏi, e đã chỉnh size font chữ cho 2 màn hình là xhdpi và xxhdpi, nhưng sao nó cứ bị chèn chữ. Màn hình bị chèn chữ kia là vsmart 2322x1080 480dpi. </p>
Answer