Android 9 (API düzeyi 28) ve sonraki sürümlerde kullanılabilen büyüteç widget'ı,
View öğesinin genişletilmiş bir kopyasını bir
gösteren bölme panelidir. Bu özellik, metin eklemeyi iyileştirir
kullanıcı deneyimi seçenekleri sunun. Büyüteç metne uygulanırken kullanıcı
büyüteçleri görüntüleyerek imleci veya seçim tutamaçlarını hassas bir şekilde konumlandırın
bir bölmede parmaklarını takip eden bir metin yazar.
Şekil 1'de büyütecin metin seçmeyi nasıl kolaylaştırdığı gösterilmektedir. Büyüteç API'leri
bir şablondan ibaret değildir ve bu widget'ı çeşitli kullanım durumlarında kullanabilirsiniz:
küçük metinleri okumak veya Haritalar'da görülmesi zor yer adlarını büyütmek gibi.
Şekil 1. Metin büyütülüyor. Kullanıcı doğru seçimi sürüklediğinde
tutma yerine, doğru yerleşim için büyüteç açılır.
Büyüteç, TextView gibi platform widget'larıyla zaten entegre edilmiştir.
EditText ve WebView. Uygulamalar arasında tutarlı metin değişiklikleri sağlar.
Widget, basit bir API ile birlikte gelir ve herhangi bir View öğesini büyütmek için kullanılabilir.
bazı en iyi uygulamalardan bahsedeceğiz.
API kullanımı
Büyüteci rastgele bir görünümde aşağıdaki şekilde programatik olarak kullanabilirsiniz:
Görünüm hiyerarşisinin ilk düzene sahip olduğu varsayıldığında, büyüteç
ekranı içerir ve görünümün içinde belirtilen koordinatlara ortalanmış bir bölgeyi içerir.
Bölme, kopyalanan içeriğin merkez noktasının üzerinde görünür. İlgili içeriği oluşturmak için kullanılan
Kullanıcı kapatana kadar büyüteç süresiz olarak geçerliliğini korur.
Aşağıdaki kod snippet'inde, büyütülmüş reklam öğesinin arka planının nasıl değiştirileceği gösterilmektedir
görünüm:
Kotlin
view.setBackgroundColor(...)
Java
view.setBackgroundColor(...);
Arka plan renginin büyüteç içinde görülebildiği varsayıldığında, büyüteçteki
içeriğin eski olması, dolayısıyla görünümün eski arka planıyla
görüntüler. İçeriği yenilemek için
update() yöntemini kullanın:
Büyüteç için yaygın bir kullanım alanı, kullanıcının bir görünüm bölgesini
dokunun. Şekil 2'de gösterildiği gibidir.
Şekil 2. Büyüteç, kullanıcının dokunuşunu takip eder. Evet
sol tarafta "ImageView" içeren bir ViewGroup için uygulandı
ve sağ tarafta TextView bulunur.
Büyüteci, alınan dokunma etkinliklerine göre güncelleyerek bunu yapabilirsiniz
aşağıdaki şekilde görebilirsiniz:
imageView.setOnTouchListener(newView.OnTouchListener(){@OverridepublicbooleanonTouch(Viewv,MotionEventevent){switch(event.getActionMasked()){caseMotionEvent.ACTION_DOWN:// Fall through.caseMotionEvent.ACTION_MOVE:{finalint[]viewPosition=newint[2];v.getLocationOnScreen(viewPosition);magnifier.show(event.getRawX()-viewPosition[0],event.getRawY()-viewPosition[1]);break;}caseMotionEvent.ACTION_CANCEL:// Fall through.caseMotionEvent.ACTION_UP:{magnifier.dismiss();}}returntrue;}});
Metin büyütürken dikkat edilmesi gereken diğer noktalar
Platform metin widget'ları için belirli bir büyüteci anlamak önemlidir.
özel metin görünümünüz için büyüteci tutarlı bir şekilde etkinleştirmek üzere
çok faydalı oluyor. Aşağıdakileri göz önünde bulundurun:
Kullanıcı bir araya ekleme düğmesi aldığında veya
seçim tutamacı.
Büyüteç, kullanıcının parmağını her zaman yatay olarak takip ederken
dikey olarak geçerli metin satırının ortasına sabitlenir.
Yatay hareket ettirildiğinde, büyüteç yalnızca sol ve sol ile
mevcut satırın sağ sınırları. Ayrıca, kullanıcı dokunduğunda
dokunma ile en yakın temas noktası arasındaki yatay mesafeyi
büyüteç içeriğinin orijinal genişliğinin yarısından daha büyüktür,
İmleç artık
büyüteç.
Metin yazı tipi çok büyük olduğunda büyüteç hiçbir zaman tetiklenmez. Metin (şimdiki değeri)
yazı tipinin eğimi ve eğimi arasındaki farkın çok büyük olduğu
büyütece sığan içeriğin yüksekliğinden daha büyüktür.
Bu durumda büyüteci tetiklemeniz değer katmaz.
Bu sayfadaki içerik ve kod örnekleri, İçerik Lisansı sayfasında açıklanan lisanslara tabidir. Java ve OpenJDK, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-07-27 UTC.
[[["Anlaması kolay","easyToUnderstand","thumb-up"],["Sorunumu çözdü","solvedMyProblem","thumb-up"],["Diğer","otherUp","thumb-up"]],[["İhtiyacım olan bilgiler yok","missingTheInformationINeed","thumb-down"],["Çok karmaşık / çok fazla adım var","tooComplicatedTooManySteps","thumb-down"],["Güncel değil","outOfDate","thumb-down"],["Çeviri sorunu","translationIssue","thumb-down"],["Örnek veya kod sorunu","samplesCodeIssue","thumb-down"],["Diğer","otherDown","thumb-down"]],["Son güncelleme tarihi: 2025-07-27 UTC."],[],[],null,["# Implement a text magnifier\n\nTry the Compose way \nJetpack Compose is the recommended UI toolkit for Android. Learn how to use text in Compose. \n[Modifier.magnifier() →](/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).magnifier(kotlin.Function1,kotlin.Function1,kotlin.Float,androidx.compose.foundation.MagnifierStyle,kotlin.Function1)) \n\n\u003cbr /\u003e\n\nAvailable in Android 9 (API level 28) and later, the magnifier widget is a\nvirtual magnifying glass that displays an enlarged copy of a `View` through an\noverlay pane that represents the lens. The feature improves the text insertion\nand selection user experience. When applying the magnifier to text, a user can\nprecisely position the cursor or the selection handles by viewing the magnified\ntext in a pane that follows their finger.\n\nFigure 1 shows how the magnifier facilitates selecting text. The magnifier APIs\naren't tied to text, and you can use this widget in a variety of use cases, such\nas reading small text or enlarging hard-to-see place names on maps.\n**Figure 1.** Magnifying text. When the user drags the right selection handle, the magnifier pops up to help with accurate placement.\n\nThe magnifier is already integrated with platform widgets such as `TextView`,\n`EditText`, and `WebView`. It provides consistent text manipulation across apps.\nThe widget comes with a simple API and can be used to magnify any `View`\ndepending on your app's context.\n\nAPI usage\n---------\n\nYou can use the magnifier programmatically on an arbitrary view as follows: \n\n### Kotlin\n\n```kotlin\nval view: View = findViewById(R.id.view)\nval magnifier = Magnifier.Builder(view).build()\nmagnifier.show(view.width / 2.0f, view.height / 2.0f)\n```\n\n### Java\n\n```java\nView view = findViewById(R.id.view);\nMagnifier magnifier = new Magnifier.Builder(view).build();\nmagnifier.show(view.getWidth() / 2, view.getHeight() / 2);\n```\n\nAssuming the view hierarchy has the first layout, the magnifier displays on the\nscreen and contains a region centered on the given coordinates within the view.\nThe pane appears above the center point of the content being copied. The\nmagnifier persists indefinitely until the user dismisses it.\n| **Note:** The arguments of [`show()`](/reference/android/widget/Magnifier#show(float,%20float)) are relative to the top-left corner of the view being magnified.\n\nThe following code snippet shows how to change the background of the magnified\nview: \n\n### Kotlin\n\n```kotlin\nview.setBackgroundColor(...)\n```\n\n### Java\n\n```java\nview.setBackgroundColor(...);\n```\n\nAssuming the background color is visible within the magnifier, the magnifier's\ncontent is stale, as a region of the view with the old background still\ndisplays. To refresh the content, use the\n[`update()`](/reference/android/widget/Magnifier#update()) method, as follows: \n\n### Kotlin\n\n```kotlin\nview.post { magnifier.update() }\n```\n\n### Java\n\n```java\nview.post(magnifier::update);\n```\n| **Note:** Post the update operation to make sure that by the time this executes, the view with the new background color is already drawn. This is because the magnifier content always stays a frame behind the magnified view.\n\nWhen finished, close the magnifier by calling the\n[`dismiss()`](/reference/android/widget/Magnifier#dismiss()) method: \n\n### Kotlin\n\n```kotlin\nmagnifier.dismiss()\n```\n\n### Java\n\n```java\nmagnifier.dismiss();\n```\n\nMagnify on user interaction\n---------------------------\n\nA common use case for the magnifier is to let the user enlarge a view region by\ntouching it, as shown in figure 2.\n**Figure 2.** The magnifier follows the user's touch. It is applied to a `ViewGroup` that contains an \\`ImageView\\` to the left and a `TextView` to the right.\n\nYou can do this by updating the magnifier according to the touch events received\nby the view, as follows: \n\n### Kotlin\n\n```kotlin\nimageView.setOnTouchListener { v, event -\u003e\n when (event.actionMasked) {\n MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE -\u003e {\n val viewPosition = IntArray(2)\n v.getLocationOnScreen(viewPosition)\n magnifier.show(event.rawX - viewPosition[0], event.rawY - viewPosition[1])\n }\n MotionEvent.ACTION_CANCEL, MotionEvent.ACTION_UP -\u003e {\n magnifier.dismiss()\n }\n }\n true\n}\n```\n\n### Java\n\n```java\nimageView.setOnTouchListener(new View.OnTouchListener() {\n @Override\n public boolean onTouch(View v, MotionEvent event) {\n switch (event.getActionMasked()) {\n case MotionEvent.ACTION_DOWN:\n // Fall through.\n case MotionEvent.ACTION_MOVE: {\n final int[] viewPosition = new int[2];\n v.getLocationOnScreen(viewPosition);\n magnifier.show(event.getRawX() - viewPosition[0],\n event.getRawY() - viewPosition[1]);\n break;\n }\n case MotionEvent.ACTION_CANCEL:\n // Fall through.\n case MotionEvent.ACTION_UP: {\n magnifier.dismiss();\n }\n }\n return true;\n }\n});\n```\n| **Note:** The magnifier never displays magnified content that doesn't belong to the view, even when the view is included in scrollable containers and partially masked. When the coordinates passed to `show()` imply copying outside content, they are coerced inside the visible region of the view.\n\nAdditional considerations when magnifying text\n----------------------------------------------\n\nFor the platform text widgets, it's important to understand specific magnifier\nbehaviors and to enable the magnifier for your custom text view consistently\nacross the Android platform. Consider the following:\n\n- The magnifier is triggered immediately when the user grabs an insertion or selection handle.\n- The magnifier always smoothly follows the user's finger horizontally, while vertically it is fixed to the center of the current text line.\n- When moving horizontally, the magnifier moves only between the left and right bounds of the current line. Moreover, when the user's touch leaves these bounds and the horizontal distance between the touch and the closest bound is larger than half of the original width of the magnifier content, the magnifier is dismissed, as the cursor is no longer visible inside the magnifier.\n- The magnifier is never triggered when the text font is too large. Text is considered too large when the difference between the font's descent and ascent is larger than the height of the content that fits in the magnifier. Triggering the magnifier in this case doesn't add value."]]