I'm making a market application as a project for my university. As such I am loading products from my database and need to display them in a list for which I want to use a ScrollView since I am fairly certain that all of the data will not be displayable on the screen at once.
I gave the ScrollView and the included LinearLayout inside the ScrollView all tags I thought necessary to contain all of that and then started adding TextViews with the informations about the products and added those into the LinearLayout but when trying to run this on the emulator the last object at the very bottom of the LinearLayout gets cut off roughly in the middle.
I've been looking around for ways to fix this after I couldn't come up with anything but nothing worked, I've seen here the ideas of making the scrollview's gravity centered and that didn't work, center_vertical didn't either, giving it the attribute android:fillViewPort="true" did nothing either android:layout_weight="1" had no effect and android:orientation="vertical" has been in there ever since I initialized the ScrollView.
So I'm kind of baffled at this because even if i try to resize the LinearLayout via Hardcoding it to expand by 1000px every time an object is added, that doesn't do anything, in fact up until hardcoding 6000px onto the Layout it doesn't even respond in any meaningful way and at that point it just basically duplicates itself but without any content. I don't understand what is going wrong. So this I pose as a question to you.
The following contains the XML code for the entire activity layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/parentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/base_content"
tools:showIn="#layout/activity_basic_list">
<View
android:id="#+id/bar"
android:layout_width="match_parent"
android:layout_height="62dp"
android:background="#color/base_bar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</View>
<ToggleButton
android:id="#+id/menu"
android:layout_width="62dp"
android:layout_height="62dp"
android:background="#color/base_bar"
android:contentDescription="#string/menu"
android:textOff="+"
android:textOn="-"
android:textSize="32sp"
app:layout_constraintStart_toStartOf="#id/bar"
app:layout_constraintTop_toTopOf="#id/bar" />
<EditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="99dp"
android:layout_marginLeft="99dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="99dp"
android:layout_marginRight="99dp"
android:backgroundTint="#000000"
android:ems="10"
android:hint="#string/search"
android:inputType="text"
android:textColor="#000000"
android:textColorHint="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/bar" />
<ImageButton
android:id="#+id/home"
android:layout_width="62dp"
android:layout_height="62dp"
android:layout_marginStart="177dp"
android:layout_marginLeft="177dp"
android:layout_marginEnd="177dp"
android:layout_marginRight="177dp"
android:background="#color/base_bar"
android:contentDescription="#string/logo_desc"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#android:drawable/btn_dialog" />
<ScrollView
android:layout_width="409dp"
android:layout_height="465dp"
android:layout_marginTop="188dp"
android:layout_weight="2"
android:fillViewport="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" />
</ScrollView>
</android.support.constraint.ConstraintLayout>
And here is also the Code of the java segment that adds Views to the Layout:
for(int i = 0; i < jarray_stock.length(); i++){
System.out.println(i);
try {
JSONObject jobj = jarray_stock.getJSONObject(i);
TextView tv = new TextView(getApplicationContext());
// tv.setWidth(1000);
// tv.setHeight(500);
tv.setLayoutParams(new LinearLayout.LayoutParams(1000, 500));
// tv.setGravity(Gravity.CENTER_VERTICAL);
tv.setBackgroundColor(getColor(R.color.error_content));
tv.setX(0);
tv.setY(i * (40));
tv.append("\n Name: " + jobj.getString("article_name"));
tv.append("\n Fach: " + jobj.getString("article_module"));
tv.append("\n ISBN: " + jobj.getString("ISBN"));
tv.append("\n Zustand: " + jobj.getString("status"));
tv.append("\n\n Verkäufer: " + jobj.getString("selling_user"));
tv.append("\n Preis: " + jobj.getString("price"));
tv.append("\n");
tv.getLayoutParams().height = LinearLayout.LayoutParams.WRAP_CONTENT;
Button jB = new Button(getApplicationContext());
jB.setWidth(50);
jB.setHeight(50);
jB.setX(750);
jB.setY(225+(i*(500 + 40)));
jB.setTextSize(17);
jB.setText(">>>");
jB.setTextColor(Color.WHITE);
jB.setBackgroundColor(getColor(R.color.base_active));
// parent_content.setMinimumHeight((jarray_stock.length() * 40) + 2000);
parent_content.addView(tv);
// parent_content.addView(jB);
tv.requestLayout();
} catch (JSONException e) {
e.printStackTrace();
}
}
Oh and the Button being created in there is not added, that line is commented out on purpose, I want to fix the problem with the ScrollView before fondling around with the button placement, that's also why the location assignment doesn't make any sense currently.
Thank you for your patience.
Put below code:
<LinearLayout
android:id="#+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" />
Related
Android version 11.0.4
I am trying to use a ListView to display a series of elements with different types of information to display in the same list using a custom ListAdapter.
To make the same ListAdapter able to display different types of information I'm creating a custom XML template with all possible elements that I want to display and hiding the ones I don't want to show programmatically.
However, when I hide the extra elements I don't want to show the size of the view displaying them shrinks.
When the extra elements are shown
When the extra elements are gone
The code that hides the elements:
TextView catagory = (TextView) convertView.findViewById(R.id.title);
TextView time1 = (TextView) convertView.findViewById(R.id.time1);
TextView time2 = (TextView) convertView.findViewById(R.id.time2);
TextView location = (TextView) convertView.findViewById(R.id.location);
TextView description = (TextView) convertView.findViewById(R.id.description);
View separator1 = (View) convertView.findViewById(R.id.separator_vertical1);
View separator2 = (View) convertView.findViewById(R.id.separator_horizontal1);
View separator3 = (View) convertView.findViewById(R.id.separator_vertical2);
View separator4 = (View) convertView.findViewById(R.id.separator_horizontal2);
catagory.setText(item.name);
Class type = item.getType();
if (EventItem.class.equals(type)) {
time1.setText(String.valueOf(((EventItem)item).timeStart));
time2.setText(String.valueOf(((EventItem)item).timeEnd));
location.setText(((EventItem)item).location);
description.setText(((EventItem)item).description);
} else if (TaskItem.class.equals(type)) {
time1.setText(String.valueOf(((TaskItem)item).timeDue));
description.setText(((TaskItem)item).description);
//hide unused elements
separator2.setVisibility(View.GONE);
location.setVisibility(View.GONE);
separator3.setVisibility(View.GONE);
time2.setVisibility(View.GONE);
} else if (ReminderItem.class.equals(type)) {
time1.setText(String.valueOf(((ReminderItem)item).time));
//hide unused elements
separator2.setVisibility(View.GONE);
location.setVisibility(View.GONE);
separator3.setVisibility(View.GONE);
time2.setVisibility(View.GONE);
separator4.setVisibility(View.GONE);
description.setVisibility(View.GONE);
} else if (SubjectItem.class.equals(type)) {
description.setText(((SubjectItem)item).description);
} else if (NoteItem.class.equals(type)) {
description.setText(((TaskItem)item).description);
//hide unused elements
separator1.setVisibility(View.GONE);
time1.setVisibility(View.GONE);
separator2.setVisibility(View.GONE);
location.setVisibility(View.GONE);
separator3.setVisibility(View.GONE);
time2.setVisibility(View.GONE);
} else if (ContactItem.class.equals(type)) {
//hide unused elements
separator1.setVisibility(View.GONE);
time1.setVisibility(View.GONE);
separator2.setVisibility(View.GONE);
location.setVisibility(View.GONE);
separator3.setVisibility(View.GONE);
time2.setVisibility(View.GONE);
}
The XML template:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/rectangle">
<TextView
android:id="#+id/title"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:textAlignment="textStart"
android:textSize="16sp"
android:textColor="#ffffffff"/>
<View
android:id="#+id/separator_vertical1"
android:layout_width="1dp"
android:layout_height="23dp"
android:layout_toStartOf="#id/time1"
android:background="#android:color/white"/>
<TextView
android:id="#+id/time1"
android:layout_width="94dp"
android:layout_height="wrap_content"
android:layout_toStartOf="#id/title"
android:layout_alignParentEnd="true"
android:textAlignment="center"
android:textSize="16sp"
android:textColor="#ffffffff"/>
<View
android:id="#+id/separator_horizontal1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#id/title"
android:background="#android:color/white"/>
<TextView
android:id="#+id/location"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_below="#id/separator_horizontal1"
android:textAlignment="textStart"
android:textSize="16sp"
android:textColor="#ffffffff"/>
<View
android:id="#+id/separator_vertical2"
android:layout_width="1dp"
android:layout_height="23dp"
android:layout_toStartOf="#id/location"
android:layout_below="#id/separator_horizontal1"
android:background="#android:color/white"/>
<TextView
android:id="#+id/time2"
android:layout_width="94dp"
android:layout_height="wrap_content"
android:layout_toStartOf="#id/location"
android:layout_below="#id/separator_horizontal1"
android:layout_alignParentEnd="true"
android:textAlignment="center"
android:textSize="16sp"
android:textColor="#ffffffff"/>
<View
android:id="#+id/separator_horizontal2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#id/location"
android:background="#android:color/white"/>
<TextView
android:id="#+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/separator_horizontal2"
android:textAlignment="textStart"
android:textSize="20sp"
android:textColor="#ffffffff"/>
The ListView the elements are displayed in:
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
android:id="#+id/text_overview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textSize="20sp"
android:textColor="#ffffffff"
android:divider="#android:color/transparent"
android:dividerHeight="8dp"
android:headerDividersEnabled="true"
android:footerDividersEnabled="true"
android:scrollbars="none"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
The answer to your question is to use View.INVISIBLE
However, when I hide the extra elements I don't want to show the size of the view displaying them shrinks.
View.GONE: This view is invisible, and it doesn't take any space for layout purposes.
View.INVISIBLE: This view is invisible, but it still takes up space for layout purposes.
Here's the link of Documentation.
Use View.INVISIBLE which takes up space and invisible the view.
while you are using View.GONE which doesn't takes up space for the view and invisible the view.
For more description, you can go with:https://developer.android.com/reference/android/transition/Visibility
I eventually got it working, not sure how but setting each element as visible before going into the if statements stoped the shrinking of the view window. It also solved the issue of some list items missing elements that shouldn't have been hidden. I can only assume some resources were being reused somewhere and arriving pre-hidden.
I am developing an android application in which I have used webview instead of Textview to use the justify property on each list item .
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical"
android:padding="10dp" >
<WebView
android:id="#+id/question"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="Question"
android:textSize="20sp" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/color_black"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:weightSum="2" >
<TextView
android:id="#+id/select_yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Yes"
android:textSize="30sp" />
<TextView
android:id="#+id/select_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="No"
android:textSize="30sp" />
</LinearLayout>
</LinearLayout>
CustomListAdapter.java
In getView()
String question = "<html><body>"
+ "<p align=\"justify\">"
+ data.get(position).getStudyCrit()
+ "</p> "
+ "</body></html>";
holder.question.loadData(question, "text/html", "utf-8");
If I run the application, the
But,After I change the scroll position and again go to previous position. the height of webview is increased like below,
Note : There is no issues with TextView, the problem arised when I replaced TextView with WebView
Please help me finding the solution.
You can use TextView instead of WebView and in TextView you can set text like:
textView.setText(Html.fromHtml(question));
And you can define maxLines for TextView.
You don't need to use webview just to justify the content. You can use the following code:
String question = "<html><body>"
+ "<p align=\"justify\">"
+ data.get(position).getStudyCrit()
+ "</p> "
+ "</body></html>";
yourtextview.setText(Html.fromHtml(question));
I am designing an Android XML layout that contains a few ImageViews representing images of checkmarks and red Xs. I have run into a few issues with these images containing extra margin/padding when presented to the screen.
Notice that there appears to be no Right or Left margin/padding but there is plenty of top/bottom padding.
The images are PNG formats following the guidelines for creating Small/Context Icons described at http://developer.android.com/design/style/iconography.html
I would like to correct the issue by having the margin/padding match the effect of its horizontal margin/padding.
Here is the XML of the layout:
<!-- Event Reoccuring -->
<LinearLayout
android:id="#+id/event_reoccur_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="5dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
>
<TextView
android:id="#+id/kid_event_reoccur_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_gravity="center_vertical"
android:text="#string/event_reoccur"
/>
<ImageView
android:id="#+id/kid_event_reoccur_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:layout_gravity="center_vertical"
android:contentDescription="#string/indicator"
/>
<TextView
android:id="#+id/kid_event_reoccur"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:layout_gravity="center_vertical"
android:paddingLeft="4dp"
android:text="#string/not_applicable"
/>
</LinearLayout>
<!-- Age Required -->
<LinearLayout
android:id="#+id/event_age_req_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp"
>
<TextView
android:id="#+id/kid_event_age_req_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_gravity="center_vertical"
android:text="#string/event_age_req"
/>
<ImageView
android:id="#+id/kid_event_age_req_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:gravity="center_vertical"
android:contentDescription="#string/indicator"
/>
<TextView
android:id="#+id/kid_event_age_req"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:layout_gravity="center_vertical"
android:paddingLeft="4dp"
android:text="#string/not_applicable"
/>
</LinearLayout>
Here is the code that populates the ImageViews (Note - mReoccurIndcator & mAgeReqIndicator are ImageViews while mReoccurence & mAgeReq are TextViews):
#TargetApi(16)
private void setupEventReoccurence(View v) {
// Get Reference
mReoccurence = (TextView) v.findViewById(R.id.kid_event_reoccur);
mReoccurence.setText(boolToString(mEvent.isReoccuring()));
// Checkmark/X indicator
mReoccurIndicator = (ImageView) v.findViewById(R.id.kid_event_reoccur_indicator);
mReoccurIndicator.setImageResource(R.drawable.greencheck_small_context_icon);
mReoccurIndicator.setScaleType(ScaleType.CENTER_INSIDE);
mReoccurIndicator.setCropToPadding(true);
//mReoccurIndicator.setMaxHeight((int) mReoccurence.getTextSize());
//mReoccurIndicator.setMinimumHeight((int) mReoccurence.getTextSize());
Log.d(TAG, "getTextSize() as float: " + mReoccurence.getTextSize());
Log.d(TAG, "getTextSize() as int: " + (int) mReoccurence.getTextSize());
}
#TargetApi(16)
private void setupEventAgeReq(View v) {
// Get Reference
mAgeReq = (TextView) v.findViewById(R.id.kid_event_age_req);
mAgeReq.setText(boolToString(mEvent.isAgeReq()));
// Checkmark/X indicator
mAgeReqIndicator = (ImageView) v.findViewById(R.id.kid_event_age_req_indicator);
mAgeReqIndicator.setImageResource(R.drawable.greencheck_small_context_icon);
mAgeReqIndicator.setScaleType(ScaleType.CENTER_INSIDE);
mAgeReqIndicator.setCropToPadding(true);
//mAgeReqIndicator.setMaxHeight((int) mReoccurence.getTextSize());
//mAgeReqIndicator.setMinimumHeight((int) mReoccurence.getTextSize());
Log.d(TAG, "getTextSize() as float: " + mReoccurence.getTextSize());
Log.d(TAG, "getTextSize() as int: " + (int) mReoccurence.getTextSize());
}
Just found a solution through another question:
Unwanted padding around an ImageView
android:adjustViewBounds="true" on the ImageView XML object solves issue.
Well you can also do something like below
ImageView image = new ImageView(this);
image.setAdjustViewBounds(true);
image.setImageResource(R.drawable.image_file);
Use RelativeLayout instead of LinearLayout. Also, try to avoid using attributes like weight unless it is necessary.
So im using this awesome Cards library (CardsUI) and trying to figure out how to insert my own text into these views grammatically. Im my main activity im parsing JSON data, now i want to use data from the JSON and insert the text into the Cards. Here is some code i have so far.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_enlighten);
// the id title is referencing the title in my card layout below
system_id = (TextView) findViewById(R.id.title);
system_name = (TextView) findViewById(R.id.system_name);
CardUI mCardView = (CardUI) findViewById(R.id.cardUI1);
mCardView.setSwipeable(false);
// add AndroidViews Cards
mCardView.addCard(new MyCard("Get the CardsUI view"));
mCardView.addCardToLastStack(new MyCard("for Android at"));
MyCard androidViewsCard = new MyCard("www.androidviews.net");
mCardView.addCardToLastStack(androidViewsCard);
// draw cards
mCardView.refresh();
// Here is my JSON Parsing activity.
new ProgressTask(WelcomeYou.this).execute();
}
My Card Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp" >
<TextView
android:id="#+id/title"
style="#style/CardTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="title" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginTop="4dp"
android:background="#color/stroke" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/selectable_background_cardbank"
android:gravity="center_vertical"
android:padding="4dp" >
<TextView
android:id="#+id/description"
style="#style/CardText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:ellipsize="end"
android:maxLines="4"
android:text="description" />
</LinearLayout>
</LinearLayout>
Im simply trying to put text into the here mCardView.addCard(new MyCard("PUT JSON STRING HERE"));
I know this question was posted a while ago, but I'm just now using the CardUI and I've got it to work. I don't know what R.id.activity_hello_enlighten contains, but if you look at the example provided with their source, the layout from your activity should be using a CardUI component.
Code from the example layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.fima.cardsui.views.CardUI
android:id="#+id/cardsview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Otherwise there's nothing actually doing your card rendering to the screen.
Once you do this, get a pointer to the CardUI referenced by your layout (in the example code it's called cardsview) with the following code:
mCardView = (CardUI) findViewById(R.id.cardsview);
After that, it's as simple as adding a new card like this:
mCardView.addCardToLastStack(new MyCard("Your card's text!"));
I have a list of articles in a listView with text on the left, and an image on the right. If the article doesn't have an image, I'd like the text to go full-width (as opposed to having a marginRight of 60dp).
My noob-java thought process is: I'm already looping through and checking if there's an image... (if there is one, I change which image shows up) within that loop, can I somehow use java to alter the XML of my view to add or remove the imageView and add or remove the margin?
The code I'm using to repeat through and alter the image:
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage("", viewHolder.thumbView); //clears previous one
if(article.filepath != null && article.filepath.length() != 0) {
imageLoader.displayImage(
"http://img.mysite.com/processes/resize.php?image=" + article.filepath + "&size=100&quality=70",
viewHolder.thumbView
);
}
My "article_entry_list_adapter.xml":
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout for individual news entries in a list -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp" >
<!-- Title of the news entry -->
<TextView
android:id="#+id/article_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="60dp"
android:textSize="13sp"
android:textStyle="bold"
android:textColor="#drawable/list_title_selector" android:typeface="serif"/>
<!-- Subtitle contains author and date -->
<TextView
android:id="#+id/article_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="60dp"
android:layout_alignLeft="#id/article_title"
android:layout_below="#id/article_title"
android:textSize="11sp"
android:textColor="#drawable/list_subtitle_selector" />
<com.sltrib.views.WebImageView
android:id="#+id/article_thumbnail"
android:layout_width="50dp"
android:layout_height="50dp"
android:adjustViewBounds="true"
android:layout_alignParentRight="true"
android:background="#color/super_light_gray"
android:padding="1dp"
android:scaleType="centerCrop" android:cropToPadding="true"/>
</RelativeLayout>
I would suggest changing your xml layout to something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp" >
<!-- Title of the news entry -->
<com.sltrib.views.WebImageView
android:id="#+id/article_thumbnail"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:adjustViewBounds="true"
android:background="#color/super_light_gray"
android:cropToPadding="true"
android:padding="1dp"
android:scaleType="centerCrop"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:layout_toLeftOf="#id/article_thumbnail"
android:orientation="vertical" >
<TextView
android:id="#+id/article_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Titol"
android:textColor="#drawable/list_title_selector"
android:textSize="13sp"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:id="#+id/article_subtitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Subtitol"
android:textColor="#drawable/list_subtitle_selector"
android:textSize="11sp" />
</LinearLayout>
Then, when there is no image, just set the WebImageView visibility to GONE and the text will take the parent's width.
With your example:
viewHolder.thumbView.setVisibility(View.VISIBLE); //to show the image
viewHolder.thumbView.setVisibility(View.GONE); //to hide the image
You can either alter your viewGroup (setting visibility of your imageView to GONE and adding a margin programmatically) or choose to inflate another xml. As you want to do =)
Just while looping setVisiblity(VIEW.Gone) of article_thumbnail.
TextView textView = (TextView) findViewById(R.id.textView1);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
llp.setMargins(50, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
textView.setLayoutParams(llp);