I can't put a picture in.



  • There's no error in the compilation, but the pictures don't come out only three blue squares.

    java

    super.onCreate(savedInstanceState);
    setContentView(R.layout.inv);
    TextView textEl = (TextView) findViewById(R.id.textView);
    

    int strId = getResources().getIdentifier("article", "string", getPackageName());
    String strValue = getString(strId);
    textEl.setText(Html.fromHtml(strValue));

    xml

    <string name="article" formatted="false"><![CDATA[
    <img src="@res/mipmap-hdpi/ic_launcher">
    <img src="@res/mipmap-hdpi/ic_launcher.png">
    <img src="file:///С:/Android/testV7/app/src/main/res/qwerty.png"/>

    marking

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    &lt;LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" &gt;
    
        &lt;Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Go to Activity One"
            android:id="@+id/btnActOne"/&gt;
    &lt;/LinearLayout&gt;
    
    &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" &gt;
    
        &lt;LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" &gt;
    
            &lt;Button
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Button 1" /&gt;
    
            &lt;TextView
                android:id="@+id/textView"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="50dp"
                android:text="nope"/&gt;
    
            &lt;Button
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Button 11" /&gt;
        &lt;/LinearLayout&gt;
    &lt;/ScrollView&gt;
    

    </LinearLayout>



  • I understand you want to put a text with pictures in textView html. TextView doesn't take pictures, they're only for text, it's more appropriate for your purposes. https://developer.android.com/reference/android/webkit/WebView.html ♪ Also, html documents are stored in Assets, a special record for styles, instead of resources. Best use:

    WebView wv= (WebView)findViewById(R.id.webView1);
    wv.loadUrl("file:///android_asset/yourfile.html");
    

    It is also possible to use a document password, e.g. jsoup, and to build a xml file in the Android.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2