The official documentation of the constraint set connect says: https://developer.android.com/reference/android/support/constraint/ConstraintSet.html#connect(int, int, int, int, int)
void connect (int startID,
int startSide,
int endID,
int endSide,
int margin)
the margin to constrain (margin must be postive)
For my understanding if I want to connect two views with the left to right of then this margin is left margin.
//left to right of
constraintset.connect(textView.id,ConstraintSet.LEFT,previousTextViewId,ConstraintSet.RIGHT,10)
then 10 is the left margin. Am I right? I have implemented this concept but no margin is set even no right or left. What am I missing?
Update: It looks like this issue has been fixed, but I haven't checked it out. See the bug report.
Your understanding is also how I understand things. Here is a quick way to check how things are working.
In the layout below, the top left corner of textRight lines up with the lower right corner of textLeft. When MainActivity runs, textRight should move 1,000px down and 1,000px to the right. It moves 1,000 px down but does not move to the right at all.
I believe that this is an outstanding issue. See this issue report.
I don't know a work-around and I am surprised that this could even be a bug. I am willing to stand corrected if anyone sees the error.
two_text_views.xml
<?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/layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp" />
<TextView
android:id="#+id/textRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView2"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="#+id/textLeft"
app:layout_constraintStart_toEndOf="#+id/textLeft"
android:layout_marginStart="0dp" />
</android.support.constraint.ConstraintLayout>
**MainActivity.java**
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
ConstraintLayout layout;
super.onCreate(savedInstanceState);
setContentView(R.layout.two_text_views);
ConstraintSet constraints = new ConstraintSet();
constraints.clone(layout);
constraints.connect(R.id.textRight, ConstraintSet.LEFT, R.id.textLeft, ConstraintSet.RIGHT, 1000);
constraints.connect(R.id.textRight, ConstraintSet.TOP, R.id.textLeft, ConstraintSet.BOTTOM, 1000);
constraints.applyTo(layout);
}
}
EDIT So, here is a fix. Use ConstraintSet.START and ConstraintSet.END instead of ConstraintSet.LEFT and ConstraintSet.RIGHT. I just tried it and it works OK. I can't say why left and right don't work.
Related
I created a custom Tab with ConstraintLayout, I decided to use ConstraintSet and TransitionManager for animating the tab selection.
This is the animation I need.
But when I implemented the animation I had problems.
Here is my code:
Xml layout definition
<android.support.constraint.ConstraintLayout
android:id="#+id/card_constraint_canvas"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- View on which I want to apply constraint for animation -->
<View
android:id="#+id/tab_selection"
android:layout_width="0dp"
android:layout_height="4dp"
android:background="#color/colorSoftBlue"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#+id/divider"
app:layout_constraintBottom_toBottomOf="parent"/>
<!-- Centered grey divider bar, view which is my anchor point -->
<View
android:id="#+id/divider"
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/colorDividerGrey"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Java code
#BindView(R.id.tab_selection) View tabSelection;
#BindView(R.id.card_constraint_canvas) ConstraintLayout cardConstraintCanvas;
...
applyConstraintSet.clone(cardConstraintCanvas); // Working
TransitionManager.beginDelayedTransition(cardConstraintCanvas); // Working
applyConstraintSet.clear(R.id.tab_selection); // Working
applyConstraintSet.connect(R.id.tab_selection, ConstraintSet.LEFT, R.id.divider, ConstraintSet.RIGHT); // Working
applyConstraintSet.connect(R.id.tab_selection, ConstraintSet.RIGHT, R.id.card_constraint_canvas, ConstraintSet.RIGHT); // Working
applyConstraintSet.connect(R.id.tab_selection, ConstraintSet.BOTTOM, R.id.card_constraint_canvas, ConstraintSet.BOTTOM); // Working
// Not working, the animation behaves strange, the tab_selection view disappears, I put 0 as width because I defined in the xml like that (0dp) but not working
// applyConstraintSet.constrainWidth(R.id.tab_selection, 0);
// Working, but I want my tab_selection view width spread at divider's start edge and parent's end edge after the animation, not a constant dimension
applyConstraintSet.constrainWidth(R.id.tab_selection, 10);
applyConstraintSet.constrainHeight(R.id.tab_selection, 10); // Working
applyConstraintSet.applyTo(cardConstraintCanvas); // Working
I suppose the problem is at constraintWidth. I also try this method for removing only the anchor and maintaining the width and the height.
void clear (int viewId, int anchor)
But I think it doesn't work as I thought.
Any thoughts?
Thank you for the help :)
If you remove the line
applyConstraintSet.clear(R.id.tab_selection);
and change ConstraintSet.LEFT and ConstraintSet.RIGHT to ConstraintSet.START and ConstraintSet.END respectively to be consistent with the naming of attributes used in the XML then this animation will work as intended.
I'm not sure why the clear method is causing the unwanted behaviour.
For training purposes, I am currently replicating the 2048 game. I got the logic and interaction done, but print (and simply refresh) it inside a single TextView which looks ridiculous, of course.
When thinking about how to build a UI for the game, I am uncertain which LayoutManager to choose. What I need to be doing in the game's 4 x 4 grid is to merge and add cells inside rows and columns with animation. It seems to me that:
GridLayout won't work since it is dealing with the full dataset (16 tiles in four rows/columns) when I need to be able to deal with single rows and columns. However, I am not sure about this. I have worked with GridLayout before, but never manipulated the number of items (add, remove) and never used animation with that manipulation. Is there a way of manipulating single rows and columns?
LinearLayout won't work since I get in trouble when I want to manipulate columns, but have four horizontal LinearLayouts, or rows, but have four vertical LinearLayouts.
RelativeLayout or ConstraintLayout would be possible - maybe. Here the trouble seems to be that I have to keep track of my 16 views, TextViews probably, and programmatically construct full layouts so I can tell animation what to do. Certainly viable, but challenging.
CustomLayout is a choice, but on which superclass should I build it and why?
Am I missing the easy solution? If not, what would be the most "natural" LayoutManager for my data structure (which is currently an array of 16 integers, but could easily be changed to a 4 x 4 array of integers).
Update: Included demo of a tile appearing and two tiles being combined.
I suggest that you go with ConstraintLayout. It will allow you to position your views efficiently and can provide you with some easy animation. I have mocked up a quick sample below to demonstrate this approach.
Here is a video of the results:
The XML layout uses ConstraintLayout as the view group. The two boxes are simply text views but could easily be image views or another type of view.
The two boxes simply move vertically between horizontal guidelines at 24dp (gdln0) and 520dp (gdln100) for textView1 and 148dp (gdln25) and 520dp (gdln100) for textView2. These movement are animated using ConstraintSet and TransitionManager through a click handler attached to the "animate" button. Here is the XML followed by the code:
activity_main.xml
<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/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.constraint.Guideline
android:id="#+id/gdln0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="24dp" />
<android.support.constraint.Guideline
android:id="#+id/gdln25"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="148dp" />
<android.support.constraint.Guideline
android:id="#+id/gdln50"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="272dp" />
<android.support.constraint.Guideline
android:id="#+id/gdln75"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="396dp" />
<android.support.constraint.Guideline
android:id="#+id/gdln100"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="520dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="24dp"
android:background="#android:color/darker_gray"
android:gravity="center"
android:text="2"
android:textColor="#android:color/white"
android:textSize="72sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/gdln0" />
<TextView
android:id="#+id/textView2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginStart="24dp"
android:background="#android:color/darker_gray"
android:gravity="center"
android:text="4"
android:textColor="#android:color/white"
android:textSize="72sp"
app:layout_constraintStart_toEndOf="#+id/textView1"
app:layout_constraintTop_toBottomOf="#id/gdln25" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:text="Animate"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private int mSquareSide;
private int mMargin;
private int mBoardState = 0;
private TextView mNewView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources r = getResources();
mSquareSide = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, r.getDisplayMetrics());
mMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, r.getDisplayMetrics());
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
ConstraintLayout layout = (ConstraintLayout) findViewById(R.id.layout);
ConstraintSet newSet = new ConstraintSet();
mBoardState = (mBoardState + 1) % 3;
switch (mBoardState) {
case 0: // Just reset the board to its starting condition.
setContentView(R.layout.activity_main);
findViewById(R.id.button).setOnClickListener(this);
break;
case 1: // Move tiles down and insert new tile.
mNewView = new TextView(layout.getContext());
mNewView.setId(View.generateViewId());
mNewView.setBackgroundColor(getResources().getColor(android.R.color.darker_gray));
mNewView.setTextSize(72);
mNewView.setTextColor(getResources().getColor(android.R.color.white));
mNewView.setText("2");
mNewView.setVisibility(View.INVISIBLE);
mNewView.setGravity(Gravity.CENTER);
ConstraintLayout.LayoutParams lp = new ConstraintLayout.LayoutParams(mSquareSide, mSquareSide);
mNewView.setLayoutParams(lp);
layout.addView(mNewView);
newSet.clone(layout);
newSet.connect(mNewView.getId(), ConstraintSet.TOP,
R.id.gdln0, ConstraintSet.BOTTOM);
newSet.connect(mNewView.getId(), ConstraintSet.START,
ConstraintSet.PARENT_ID, ConstraintSet.START, mMargin);
newSet.clear(R.id.textView1, ConstraintSet.TOP);
newSet.clear(R.id.textView2, ConstraintSet.TOP);
newSet.connect(R.id.textView1, ConstraintSet.BOTTOM,
R.id.gdln100, ConstraintSet.BOTTOM);
newSet.connect(R.id.textView2, ConstraintSet.BOTTOM,
R.id.gdln100, ConstraintSet.BOTTOM);
TransitionManager.beginDelayedTransition(layout);
newSet.applyTo(layout);
mNewView.setVisibility(View.VISIBLE);
break;
case 2: // Move tiles up and combine two tiles.
newSet.clone(layout);
newSet.clear(R.id.textView1, ConstraintSet.BOTTOM);
newSet.clear(R.id.textView2, ConstraintSet.BOTTOM);
newSet.connect(R.id.textView1, ConstraintSet.TOP,
R.id.gdln0, ConstraintSet.BOTTOM);
newSet.connect(R.id.textView2, ConstraintSet.TOP,
R.id.gdln0, ConstraintSet.BOTTOM);
Transition transition = new AutoTransition();
transition.addListener(new Transition.TransitionListener() {
#Override
public void onTransitionStart(Transition transition) {
}
#Override
public void onTransitionEnd(Transition transition) {
mNewView.setText("4");
// Here you would remove the overlapped view
// with layout.removeView(View);
}
#Override
public void onTransitionCancel(Transition transition) {
}
#Override
public void onTransitionPause(Transition transition) {
}
#Override
public void onTransitionResume(Transition transition) {
}
});
TransitionManager.beginDelayedTransition(layout, transition);
newSet.applyTo(layout);
break;
}
}
});
}
}
I think I would go with plain drawing the whole thing without using any TextView or similar.
Let me explain you why.
Assuming you have a set of 16 TextView, which is the maximum that you can have in your grid, you should manage which one is visible and which one is not, hide it or not, move it inside a layout or not. This would take up many resources and if you're using a layout like the ones you've described, a "free" transition would not be possible too.
Assume you have two tiles and you want one to slide on the other and merge them. The only usable layout I can think of is RelativeLayout because it's the one with the most easily manipulable constraints.
You'll have to deal with every TextView though, managing the gradual transition and the overlap, while making Android consider ALL the stuff a TextView can do.
Now, you'll have to do all that movement/overlapping stuff anyway, so why don't you do that by drawing each tile? You'll have to write some more code to draw an hypothetic Tile class into a canvas (note that you might change your data structure a bit).
After you have your drawing mechanism you'll have to make the same stuff you would do with TextViews, but in a different, freer, way of thinking, with fewer constraints and by using less Android resources.
I know you were asking advice about some Layout to use and I'm proposing to draw the tiles by yourself, this might not be what you needed and if I bothered you with this long talk I apologise, but if you were asking for advice in a "wider" manner I think this is a good idea to keep in mind.
And it would be a great occasion to learn about 2d drawing on Android too!
Happy coding!
I am trying to design the below layout
<android.support.constraint.ConstraintLayout
android:id="#+id/before_breakfast_option"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/diabetes_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:text="water"
android:textAppearance="#style/TextAppearance.AppCompat.Medium"
android:textColor="#color/black"
app:layout_constraintBaseline_toBaselineOf="#+id/toogle_diabeties"
app:layout_constraintLeft_toLeftOf="parent"/>
<TextView
android:textColor="#color/black"
android:text="almonds"
app:layout_constraintTop_toTopOf="parent"
android:id="#+id/toogle_diabeties"
app:layout_constraintRight_toRightOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.constraint.ConstraintLayout>
using the below code:
var textView= TextView(this#DietStepFive)
textView.id=100
textView.text="water"
textView.background=ContextCompat.getDrawable(this#DietStepFive,R.drawable.rectangle_diet)
textView.setTextColor(ContextCompat.getColor(this#DietStepFive,R.color.black))
var textView1= TextView(this#DietStepFive)
textView1.id=101
textView1.text="almonds"
textView1.background=ContextCompat.getDrawable(this#DietStepFive,R.drawable.rectangle_diet)
textView1.setTextColor(ContextCompat.getColor(this#DietStepFive,R.color.black))
var constraintset= ConstraintSet()
constraintset.clone(before_breakfast_option)
//left to left of
constraintset.connect(textView.id,ConstraintSet.LEFT,ConstraintSet.PARENT_ID,ConstraintSet.LEFT,0)
//baseline
constraintset.connect(textView.id,ConstraintSet.BASELINE,textView1.id,ConstraintSet.BASELINE,0)
//right to right of
constraintset.connect(textView1.id,ConstraintSet.RIGHT,ConstraintSet.PARENT_ID,ConstraintSet.RIGHT,0)
//top to top of
constraintset.connect(textView1.id,ConstraintSet.TOP,ConstraintSet.PARENT_ID,ConstraintSet.TOP,0)
constraintset.applyTo(before_breakfast_option)
before_breakfast_option.addView(textView)
before_breakfast_option.addView(textView1)
But the XML code is giving me the layout which has two textview one is one left side and one is one right side but kotlin code is giving me the both the textview overlapping on left side. Why?
what wents wrong? any lead?
Add the TextViews to the layout then connect them just like you did when setting up the XML. You added the views THEN connected them.
Move
before_breakfast_option.addView(textView)
before_breakfast_option.addView(textView1)
before
var constraintset= ConstraintSet()
and everything should work.
Maybe anyone else will use it in future. A sound sleep and work done.
I was using the wrong constraint.
Instead of this
//left to left of
constraintset.connect(textView.id,ConstraintSet.LEFT,ConstraintSet.PARENT_ID,ConstraintSet.LEFT,0)
//baseline
constraintset.connect(textView.id,ConstraintSet.BASELINE,textView1.id,ConstraintSet.BASELINE,0)
//right to right of
constraintset.connect(textView1.id,ConstraintSet.RIGHT,ConstraintSet.PARENT_ID,ConstraintSet.RIGHT,0)
//top to top of
constraintset.connect(textView1.id,ConstraintSet.TOP,ConstraintSet.PARENT_ID,ConstraintSet.TOP,0)
use this
//left to right of
constraintset.connect(textView1.id,ConstraintSet.LEFT,textView.id,ConstraintSet.RIGHT,10)
//baseline
constraintset.connect(textView1.id,ConstraintSet.BASELINE,textView.id,ConstraintSet.BASELINE,0)
Try to replace app:layout_constraintRight_toRightOf="parent"
with
app:layout_constraintRight_toRightOf="#+id/toogle_diabeties"
I'm trying to show items in a ListView like so:
a. Name1
80.33 ====== 60%
b. Name2
101.22 ======= 70%
c. Name3
55.22 === 30%
d. Name4
140.11 ========== 100%
The "graph" should be a solid colored line but the entire width of the 100% needs to be there, and it should occupy the entire width available except for the value on the far left and the percentage on the far right. Also the percentages are more percentiles, relative to the lowest value in the set!
Anyway I have tried a FrameLayout with a ProgressBar and that seems to be ill-suited for this plus I can't get it to lay out the way I want. I'm thinking a 1px colored image that I stretch the percent I need then a 1px dark image the rest of the way.
Any ideas? My thanks!
EDIT:
ok progress but a new problem:
Here's what I did in the layout:
<View
android:id="#+id/pr_bar_1"
android:layout_width="30dip"
android:layout_height="4dip"
android:layout_gravity="center_vertical"
android:background="#ffffff" />
<View
android:id="#+id/pr_bar_2"
android:layout_width="70dip"
android:layout_height="4dip"
android:layout_gravity="center_vertical"
android:background="#333333" />
That looks exactly like what I want! However... I can't seem to set the widths dynamically now. There is no setLayoutWidth(int dip) method for the View class. If I could get that then I'd be done. Any ideas? Thanks!
As i understand you need to show dark line for scored percentage. Let me correct if i am wrong. For that you can try this:-
You can use 2 LinearLayout under 1 horizontal LinearLayout Parent. Set the Weightsum of parent Layout to 100. First LinearLayout which comes in left with dark image and second with light image. Then set the weight of left child according to percent, and give remaining percent to right LinearLayout
Answer for your edit question:
LayoutParams
params=view_instan.getLayoutParams();
params.width=yourWidth;
view_instan.setLayoutParams(params);
If you want something that custom, write your own view and override onDraw to do exactly what you want.
Using view.setLayoutParams(params) didn't work for me, I had to put the code inside a runnable.
xml:
<LinearLayout
android:id="#+id/ll_parent"
android:layout_width="match_parent"
android:layout_height="6dp"
android:baselineAligned="false"
android:orientation="horizontal"
android:background="#color/white"
android:paddingStart="1dp"
android:paddingEnd="1dp">
<LinearLayout
android:id="#+id/pr_bar_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="0"
android:layout_gravity="center_vertical"
android:background="#color/blue">
</LinearLayout>
<LinearLayout
android:id="#+id/pr_bar_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="0"
android:layout_gravity="center_vertical"
android:background="#color/white">
</LinearLayout>
</LinearLayout>
java:
final int percentage = my_percentage;
llParent.post(new Runnable() {
#Override
public void run() {
int fullWidth = llParent.getWidth();
prBar2.getLayoutParams().width = Math.round(fullWidth*((1 - ((float) (percentage/100)))));
prBar2.requestLayout();
prBar1.getLayoutParams().width = Math.round(fullWidth*((float) (percentage/100)));
prBar1.requestLayout();
}
});
I am all for reusing views in listview. I always set visibility, contents, witdth etc. of all controls again in getView Unfortunately it seems ListView fails to recalculate height.
Picture one shows the initial item showed:
Picture two shows how item one is rendered after we scrolled away and back into it
The background linearlayout height (the black area) made me think that in picture two, Android is reusing a view that just showed a much heigher item (e.g. the second item). But why does it not recalibrate/reset/recalclulate itself (it is in "wrap_content" mode in its XML) when reused as view for the first item which content (text + image) is not as heigh?
In truth I am not sure what is happening. The problem only manifests itself if I have image in the view. I have tried organize the bitmap/image loading in different ways (sample code underneath) with different things commented out, but that does not seem to make much difference. I am really at a loss here as to the reason.
override_listitem_news.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:background="#android:color/black"
>
<TextView
android:id="#+id/listitem_news_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="22sp"
android:padding="5dip"
android:text="#string/newsItemTitle"/>
<TextView
android:id="#+id/listitem_news_date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="italic"
android:textSize="15sp"
android:padding="5dip"
android:text="#string/newsItemDate"/>
<TextView
android:id="#+id/listitem_news_content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textStyle="normal"
android:textSize="15sp"
android:padding="5dip"
android:autoLink="web"
android:text="#string/newsItemDesc"
android:background="#android:color/darker_gray"
/>
<ImageView
android:id="#+id/listitem_news_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
Here is code where I load image in getView
ViewTreeObserver vto = image.getViewTreeObserver();
vto.addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
image.getViewTreeObserver().removeGlobalOnLayoutListener(this);
image.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
SharedCode.sharedUtilScaleImage_Width(image);
}
}
);
image.setTag(data.image_file_name + data.image_file_url);
Bitmap bit = null;
bit = SharedCode.sharedGetFileFromOffline(thisActivityContext, "news", data.image_file_name, MyGetKindOfFile.ImageAsBitmap).bitmap;
if (bit != null) {
image.setImageBitmap(bit);
image.setVisibility(View.VISIBLE);
}
else {
image.setImageBitmap(null);
image.setVisibility(View.GONE);
}
image.setPadding(0, 0, 0, 0);
image.setBackgroundColor(data.backgroundColorInt);
For what it is worth, problem appeared to be related to the imageview. Just for reference, I will write here how I solved it.
In getView I fixed the imageview width to screen width (instead of "wrap-content" and/or parent view width - earlier code used OnGlobalLayoutListener for parent width)
I switched over to using SetDrawable instead of SetImageBitmap. It is odd, but this difference was actual very important in solving the odd space around the imageview after scrolling an item/row in/out of view.
My research did also indicate that others had problems using wrap_content in listview for cases similar to mine, but I was not able to find anyone who had experienced exact same problems as me.