Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 文本视图中的空白_Android_Textview_Whitespace_Trim - Fatal编程技术网

Android 文本视图中的空白

Android 文本视图中的空白,android,textview,whitespace,trim,Android,Textview,Whitespace,Trim,我使用此解析器通过Html将图像下载到textview。fromHtml() 公共类URLImageParser实现Html.ImageGetter{ 上下文c; 文本视图容器; 活动a; 内质内质; 内部宽度; 布尔精加工; public int getCounterImages(){ 返回反镜像; } public void setCounterImages(int counterImages){ this.counterImages=counterImages; } 公共URLImageP

我使用此解析器通过Html将图像下载到textview。fromHtml()

公共类URLImageParser实现Html.ImageGetter{
上下文c;
文本视图容器;
活动a;
内质内质;
内部宽度;
布尔精加工;
public int getCounterImages(){
返回反镜像;
}
public void setCounterImages(int counterImages){
this.counterImages=counterImages;
}
公共URLImageParser(TextView t、上下文c、活动a){
这个.c=c;
这个容器=t;
这个a=a;
内在八度=0;
内部宽度=0;
finishedExecuting=假;
}
公共可绘制getDrawable(字符串源){
URLDAWABLE URLDAWABLE=新的URLDAWABLE();
ImageGetterAsyncTask异步任务=
新的ImageGetterAsyncTask(URLDawable);
asyncTask.execute(源代码);
返回可提取;
}
公共类ImageGetterAsyncTask扩展异步任务{
URLDrawable URLDrawable;
布尔值usesImageNotFoundDrawable=false;
公共ImageGetterAsyncTask(URLDawable d){
this.urlDrawable=d;
}
@凌驾
受保护的可抽出式doInBackground(字符串…参数){
字符串源=参数[0];
返回可提取的(源);
}
@凌驾
受保护的void onPostExecute(可提取结果){
如果(结果==null){
usesImageNotFoundDrawable=true;
//找不到绘图表,因此请使用未找到的图像
//巴布亚新几内亚
结果=a.getResources().getDrawable(未找到R.drawable.image);
}否则{
usesImageNotFoundDrawable=false;
}
断言结果!=null;
intrinsicHeight=result.getIntrinsicHeight();
intrinsicWidth=result.getIntrinsicWidth();
DisplayMetrics dm=新的DisplayMetrics();
((WindowManager)c.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(dm);
int width=dm.widthPixels-50;
内部高度=宽度*内部高度/内部宽度;
结果:立根(0,0,宽度,高度);
urlDrawable.setBounds(0,0,宽度,高度);
urlDrawable.drawable=结果;
URLImageParser.this.container.invalidate();
urlmageparser.this.container.setHeight((urlmageparser.this.container.getHeight()+height));
URLImageParser.this.container.refreshDrawableState();
//预集成电路
URLImageParser.this.container.setEllipsize(null);
setFinishedExecuting(真);
}
公共可提取可提取(字符串urlString){
试一试{
InputStream is=fetch(urlString);
返回Drawable.createFromStream(is,“src”);
}捕获(例外e){
返回null;
}
}
私有InputStream获取(字符串urlString)引发错误的InputStream异常,IOException{
DefaultHttpClient httpClient=新的DefaultHttpClient();
HttpGet请求=新的HttpGet(urlString);
HttpResponse response=httpClient.execute(请求);
返回response.getEntity().getContent();
}
}
公共布尔getFinishedExecuting(){
返回完成数据采集;
}
public void setFinishedExecuting(布尔布尔布尔值){
完成Dexecuting=bool;
}
}
每次我都会看到一个好看的文本视图,但最后会有额外的空白。我试图修改我的公式,但它在所有文本视图中也不起作用。最后如何从TextView中修剪不必要的rai高度或空白?

TextView.getText().trim()
?我不能使用此结构。
public class URLImageParser implements Html.ImageGetter {
Context c;
TextView container;
Activity a;
int intrinsicHeight;
int intrinsicWidth;
boolean finishedExecuting;

public int getCounterImages() {
    return counterImages;
}

public void setCounterImages(int counterImages) {
    this.counterImages = counterImages;
}

public URLImageParser(TextView t, Context c, Activity a) {
    this.c = c;
    this.container = t;
    this.a = a;
    intrinsicHeight =0;
    intrinsicWidth = 0;
    finishedExecuting = false;
}

public Drawable getDrawable(String source) {

    URLDrawable urlDrawable = new URLDrawable();

    ImageGetterAsyncTask asyncTask =
            new ImageGetterAsyncTask( urlDrawable);

    asyncTask.execute(source);

    return urlDrawable;
}

public class ImageGetterAsyncTask extends AsyncTask<String, Void, Drawable>  {
    URLDrawable urlDrawable;
    boolean usesImageNotFoundDrawable = false;

    public ImageGetterAsyncTask(URLDrawable d) {
        this.urlDrawable = d;
    }

    @Override
    protected Drawable doInBackground(String... params) {
        String source = params[0];
        return fetchDrawable(source);
    }

    @Override
    protected void onPostExecute(Drawable result) {

            if(result ==null){
                usesImageNotFoundDrawable = true;
                //the drawable wasn't found so use the image not found
                //png
                result = a.getResources().getDrawable(R.drawable.image_not_found);
            } else {
                usesImageNotFoundDrawable = false;
            }


            assert result != null;
            intrinsicHeight = result.getIntrinsicHeight();
            intrinsicWidth = result.getIntrinsicWidth();

            DisplayMetrics dm = new DisplayMetrics();
            ((WindowManager) c.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(dm);
            int width = dm.widthPixels -50;
            int height = width * intrinsicHeight / intrinsicWidth;

            result.setBounds(0, 0, width, height);

            urlDrawable.setBounds(0, 0, width, height);

            urlDrawable.drawable = result;

            URLImageParser.this.container.invalidate();

                              URLImageParser.this.container.setHeight((URLImageParser.this.container.getHeight() + height));

            URLImageParser.this.container.refreshDrawableState();
            // Pre ICS
            URLImageParser.this.container.setEllipsize(null);

            setFinishedExecuting(true);
    }

    public Drawable fetchDrawable(String urlString) {
        try {
            InputStream is = fetch(urlString);
            return Drawable.createFromStream(is, "src");
        } catch (Exception e) {
            return null;
        }
    }

    private InputStream fetch(String urlString) throws MalformedURLException, IOException {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet request = new HttpGet(urlString);
        HttpResponse response = httpClient.execute(request);
        return response.getEntity().getContent();
    }
}



public boolean getFinishedExecuting(){
    return finishedExecuting;
}

public void setFinishedExecuting(boolean bool){
    finishedExecuting = bool;
}