亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Android Studio,為什么包含在 LinearLayout 小部件中的

使用 Android Studio,為什么包含在 LinearLayout 小部件中的

忽然笑 2022-07-27 09:17:19
我想將“顯示”的以下部分作為圖像提取到 PNG 文件中。<LinearLayout       android:layout_width="match_parent"       android:layout_height="match_parent"       android:id="@+id/Layout">       <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"           android:layout_width="fill_parent"           android:layout_height="fill_parent">           <ImageView               android:layout_width="match_parent"               android:layout_height="fill_parent"               android:id="@+id/Image_view"               />           <TextView               android:id="@+id/text_view1"               android:layout_width="wrap_content"               android:layout_height="wrap_content"                />       </FrameLayout>   </LinearLayout>為此,我使用以下代碼list.add("Raghul s");list.add("Name 2");list.add("Name 3");for(int i=0;i<list.size();i++){LinearLayout view = (LinearLayout) findViewById(R.id.Layout);txt = (TextView) findViewById(R.id.Text_View1);txt.setText(list.get(i));view.setDrawingCacheEnabled(true);view.buildDrawingCache(true);Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());view.setDrawingCacheEnabled(false);bs = new ByteArrayOutputStream();bs.compress(Bitmap.CompressFormat.PNG, 40, bitmap);try {    file = new File("Image.png");    file.createNewFile();    ws = new FileOutputStream(file);    ws.write(bs.toByteArray());    ws.close();    } catch (Exception e)    {    e.printStackTrace();    } }當我執行此代碼時,我獲得了一個 PGN 圖像,其中 Raghul 的單詞被部分截斷,如下圖所示對于名稱 2 和名稱 3:怎么了 ?為什么“Raghul s”和“name 2”被截斷?如何解決這個問題?
查看完整描述

1 回答

?
慕姐8265434

TA貢獻1813條經驗 獲得超2個贊

我認為您的問題與您的 TextView 寬度太短而無法完全顯示您的姓名有關。

有 3 種可能性來檢查我看到的原因是否正確。

A.您刪除小部件并在 TextView 中ImageView替換為wrap_contentmatch_parent

B. 你在 TextView 小部件中添加以下屬性

android:text="xxxxxxxxxx"

view.invalidate()C.在使用以下代碼分配 TextView 后,您使用以下代碼刷新您的 LinearLayout :

txt.setText(list.get(i));
view.invalidate();

我認為(未經測試),最后一個命令將解決您的問題。

我已經添加了這個可能性

D. 你可以為 LinearLayout 中的所有小部件著色,看看會發生什么。這樣做,我們可以看到所有小部件的寬度,也許我們可以更好地了解您的問題。


查看完整回答
反對 回復 2022-07-27
  • 1 回答
  • 0 關注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號