Joe Simpson
Joe Simpson

Reputation: 2594

A part of TextView content is not visible

android is seeming to chop off my textviews for no reason.

The XML which surrounds the area is this:

<HorizontalScrollView
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:background="@android:color/background_dark"
    android:layout_width="fill_parent">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:id="@+id/suggestions">
        </LinearLayout>
</HorizontalScrollView>

And I'm programmatically adding the TextViews as follows:

LinearLayout suggestions = (LinearLayout)findViewById(R.id.suggestions);
suggestions.setVisibility(View.VISIBLE);
suggestions.removeAllViews();
for(String completion : completions){
    TextView show = new TextView(DailyboothBoothView.this);
    show.setTag(completion + " ");
    show.setText("@" + completion);
    show.setPadding(5, 5, 5, 5);
    show.setOnClickListener(new OnClickListener(){
        @Override
        public void onClick(View v) {
        // Some code here   
        }
    });
    show.setHeight(show.getLineHeight() + 10);
    show.setTextColor(Color.parseColor("#cc6600"));
    suggestions.addView(show);
}

Upvotes: 0

Views: 158

Answers (2)

EvilDuck
EvilDuck

Reputation: 4436

Try replacing:

suggestions.addView(show);

with:

suggestions.addView(show, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));

Upvotes: 1

devconsole
devconsole

Reputation: 7915

Let the view do the measuring and remove that show.setHeight(show.getLineHeight() + 10) . It looks like TextView has some kind of internal extra padding before the first line of text which you do not take into account.

Upvotes: 2

Related Questions