Why is my sepcial RTL layout still aligned to left? - java

I have RTL layout and LTR layout.
at the beginning all works great, but after moving to Alerter mode
both layouts are aligned to left.
how can I fix this? or at least better inspect the situation?
is there any tool with which I can see the current layout properties and attributes in my Activity's view? The code changes many attributes from the original XMl and it's hard to follow at a specific situation.
here is my xml:
<LinearLayout
android:id="#+id/navBarBox2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:padding="0dp"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/navBarDistanceLayout"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="gone">
<MyTextView
android:id="#+id/navBarDistance"
style="#style/NavBarDistance"
android:textSize="19dp"
android:text="miles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<MyTextView
android:id="#+id/navBarDistanceUnit"
style="#style/NavBarDistUnit"
android:textSize="19dp"
android:text="0.1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/navBarDistanceLayoutRtl"
android:layout_width="70dp"
android:layout_height="match_parent"
android:layout_marginRight="8dp"
android:layout_marginTop="5dp"
android:gravity="center_vertical|right"
android:orientation="horizontal"
android:visibility="gone">
<MyTextViewType
android:id="#+id/navBarDistanceUnitRtl"
style="#style/NavBarDistUnit"
android:textSize="19dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="3dp"
/>
<MyTextViewType
android:id="#+id/navBarDistanceRtl"
style="#style/NavBarDistance"
android:textSize="19dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
and here is parts of the code:
the change to AlerterMode and then coming back to non-alrter more makes navBarDistanceLayoutRtl be aligned to left instead of right
if (bIsAlertMode)
{
...
if (rtlMode)
{
width = view.findViewById(R.id.navBarDistanceLayoutRtl).getWidth();
android.widget.LinearLayout.LayoutParams DistanceBar = new LinearLayout.LayoutParams(width, android.widget.LinearLayout.LayoutParams.MATCH_PARENT);
DistanceBar.setMargins(3, 20, 3, 0);
view.findViewById(R.id.navBarDistanceLayoutRtl).setLayoutParams(DistanceBar);
}
else
{
width = view.findViewById(R.id.navBarDistanceLayout).getWidth();
android.widget.LinearLayout.LayoutParams DistanceBar = new LinearLayout.LayoutParams(width, android.widget.LinearLayout.LayoutParams.MATCH_PARENT);
DistanceBar.setMargins(3, 20, 3, 0);
view.findViewById(R.id.navBarDistanceLayout).setLayoutParams(DistanceBar);
}
...
}
else
{
...
if (rtlMode)
{
width = view.findViewById(R.id.navBarDistanceLayoutRtl).getWidth();
android.widget.LinearLayout.LayoutParams DistanceBar = new LinearLayout.LayoutParams(width, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
DistanceBar.setMargins(20, 8, 3, 0);
DistanceBar.gravity = RelativeLayout.ALIGN_PARENT_RIGHT;
view.findViewById(R.id.navBarDistanceLayoutRtl).setLayoutParams(DistanceBar);
view.findViewById(R.id.navBarDistanceLayoutRtl).setVisibility(View.VISIBLE);
view.findViewById(R.id.navBarDistanceLayout).setVisibility(View.GONE);
distance = (TextView)view.findViewById(R.id.navBarDistanceRtl);
distanceUnit = (TextView)view.findViewById(R.id.navBarDistanceUnitRtl);
}
else
{
width = view.findViewById(R.id.navBarDistanceLayout).getWidth();
android.widget.LinearLayout.LayoutParams DistanceBar = new LinearLayout.LayoutParams(width, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
DistanceBar.setMargins(0, 8, 3, 0);
view.findViewById(R.id.navBarDistanceLayout).setLayoutParams(DistanceBar);
DistanceBar.gravity = RelativeLayout.ALIGN_PARENT_LEFT;
view.findViewById(R.id.navBarDistanceLayoutRtl).setVisibility(View.GONE);
view.findViewById(R.id.navBarDistanceLayout).setVisibility(View.VISIBLE);
distance = (TextView)view.findViewById(R.id.navBarDistance);
distanceUnit = (TextView)view.findViewById(R.id.navBarDistanceUnit);
}
...
}
}

android:gravity can use only for content inside of LinearLayout, TextView or other Views. if you want to RTL or LTR layout you have to use android:layout_gravity.

Related

Change layout of an existig view

I have downloaded a library from Github - https://github.com/riyagayasen/Android_accordion_view and added it as a module to my project.
I want to change the layout of the view, because the default one doesn't quite suit my design. By default it looks like this: https://pp.userapi.com/c855132/v855132038/18192/AJnXb6Z7l4c.jpg; I want it look like this: https://pp.userapi.com/c855132/v855132038/18178/VyKEhn6ERuk.jpg; but all i have achieved is this: https://pp.userapi.com/c848416/v848416709/1602db/3JjKU9eMj0g.jpg.
It is clear that I have to change the layout of the AccordionView.
The path to the layout XML is Android_accordion_view/easyaccordion/src/main/res/layout/accordion.xml
I am sure that AccordionView uses exactly this layout because there is a method in AccordionView.java that inflates this XML as a layout:
private void initializeViews(Context context) {
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//here it happens
LinearLayout accordionLayout = (LinearLayout) inflater.inflate(R.layout.accordion, null);
partition = accordionLayout.findViewById(R.id.partition);
heading = (TextView) accordionLayout.findViewById(R.id.heading);
paragraph = (RelativeLayout) accordionLayout.findViewById(R.id.paragraph_layout);
dropdownImage = (ImageView) accordionLayout.findViewById(R.id.dropdown_image);
dropupImage = (ImageView) accordionLayout.findViewById(R.id.dropup_image);
headingLayout = (LinearLayout) accordionLayout.findViewById(R.id.heading_layout);
paragraph.removeAllViews();
int i;
children = new View[getChildCount()];
for (i = 0; i < getChildCount(); i++) {
children[i] = getChildAt(i);
}
removeAllViews();
for (i = 0; i < children.length; i++) {
paragraph.addView(children[i]);
}
paragraphBottomMargin = ((LinearLayout.LayoutParams) paragraph.getLayoutParams()).bottomMargin;
paragraphTopMargin = ((LinearLayout.LayoutParams) paragraph.getLayoutParams()).topMargin;
addView(accordionLayout);
}
The problem is that if I change accordion.xml, nothing actually changes when I add the AccordionView to my fragment's layout, and that's super weird.
I assume that I have somehing wrong in Gradle dependences or somewhere near it, but I can't figure it out.
That is the xml that I want to change the default layout to.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:layout_width="match_parent"
android:background="#drawable/accordion_background"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:id="#+id/heading_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="#+id/favourite_checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:button="#drawable/star_checkbox"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#+id/heading"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/dropup_image"
android:layout_width="34dp"
android:layout_height="26dp"
android:layout_marginTop="2dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_arrow_up"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/favourite_checkBox"
app:layout_constraintStart_toStartOf="#+id/favourite_checkBox"
app:layout_constraintTop_toBottomOf="#+id/favourite_checkBox" />
<ImageView
android:id="#+id/dropdown_image"
android:layout_width="0dp"
android:layout_height="18dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_arrow_down"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/favourite_checkBox"
app:layout_constraintStart_toStartOf="#+id/favourite_checkBox"
app:layout_constraintTop_toBottomOf="#+id/favourite_checkBox" />
<TextView
android:id="#+id/heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:text="Title"
android:textStyle="bold"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="#+id/partition"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/paragraph_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical"
android:paddingTop="10dp"
android:visibility="visible"
tools:visibility="visible">
</RelativeLayout>
</LinearLayout>
Yes, I understand that the heading layout is LinearLayout by default, but even if I change the dropdown icon size in the default layout, it stays the same when I use the view.
So my question is: how can I make the layout above appear when I use the view?
I will provide any of my code by your request.
Thank you.

Programmatic table row with text and a button

I have this layout which presents my View correctly, I tried to match it with Java side to have the capability to build rows dynamically, but I kept failing into achieving that,
<TableLayout>
android:layout_width="match_parent"
android:layout_height="wrap_content"
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="200dp"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextViewaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaws" />
</LinearLayout>
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</TableRow>
</TableLayout>
I do want to make it in code, I have tried many times and this is my best attempt
public static void makeTablePostOrders(Context ct, TableLayout tableLayout_PostOrders,
List<String> postOrders)
{
TableRow.LayoutParams tableRowParams = new TableRow.LayoutParams(
TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams linearLayoutParams = new LinearLayout.LayoutParams(200,
LinearLayout.LayoutParams.MATCH_PARENT,1);
//randoms
for(int i = 0; i < postOrders.size()/2 ; i++)
{
//make tableRow
TableRow tableRow = new TableRow(ct);
// make LinearLayout
LinearLayout layout = new LinearLayout(ct);
layout.setLayoutParams(linearLayoutParams);
layout.setOrientation(LinearLayout.VERTICAL);
//make TextView
TextView tv = new TextView(ct);
tv.setText(postOrders.get(i));
tv.setTextColor(Color.BLACK);
// make button
// the button should send us to next view
Button bt_View = new Button(ct);
bt_View.setText("Select");
//adding views
layout.addView(tv,-2,-2);
tableRow.addView(layout);
tableRow.addView(bt_View,-2,-2);
tableLayout_PostOrders.addView(tableRow,i+1);
}
}
What I want is to make table ROWs with Text and a Button, yet the text should not pass the screen and always go down vertically if needed.
here is a picture, each row will have one of these.
The correct way to implement the design according to yr requirement is listview or recyclerview.
So best to use Listview/RecycleView instead of making list row on fly.
The xml for the list row will look like :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".65"
android:text="You text will come here" />
<Button
android:id="#+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Button" />
</LinearLayout>

Set margins from textviews programmatically

Im trying to make a view where there is a static margin between textviews that i have made programmatically, how can i make this happened? I tried alot and my
setMargins(viewEvent, 20, placeSum, 0, 0);
just setting margins top from the layout and as said i want to make margins to the above textview.
Here is my loop
int set=0;
for (int i = 0; i < partEvents.length; i++) {
RelativeLayout relativeLayout = (RelativeLayout) eventView.findViewById(R.id.eventRelativeLayout);
TextView viewEvent = new TextView(getActivity());
viewEvent.setBackgroundResource(R.drawable.eventbg);
viewEvent.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
String startHour = getHourFromString(partEvents[i][2]);
String startMinute = getMinuteFromString(partEvents[i][2]);
String endHour = getHourFromString(partEvents[i][3]);
String endMinute = getMinuteFromString(partEvents[i][3]);
viewEvent.setText(partEvents[i][0]+ "\n" +
partEvents[i][1] + "\n"
+ startHour + ":" + startMinute + "-" + endHour + ":" + endMinute );
final float scale = getResources().getDisplayMetrics().density;
int placeSum = (int) (10 + set * scale + 0.5f);
setMargins(viewEvent, 20, placeSum, 0, 0);
viewEvent.setTextSize(20);
set=set+100;
try {
relativeLayout.addView(viewEvent);
} catch (Exception e) {
e.printStackTrace();
}
}
xml
<
?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/dividerView"
android:layout_alignParentBottom="true">
<LinearLayout
android:id="#+id/temp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_weight="1" >
<TextView
android:text="Event namn:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="12dp" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:id="#+id/sum"
android:gravity="center_vertical"
android:textStyle="normal|bold"
android:textSize="20sp"
android:layout_alignTop="#+id/textView"
android:layout_alignParentStart="true" />
<TextView
android:text="Beskrivning:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:layout_below="#+id/sum"
android:layout_alignParentStart="true"
android:layout_marginTop="20dp" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:gravity="center_vertical"
android:id="#+id/description"
android:textStyle="normal|bold"
android:textSize="20sp"
android:layout_alignTop="#+id/textView4"
android:layout_alignParentStart="true" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginTop="21dp"
android:id="#+id/startEvent"
android:textStyle="normal|bold"
android:textSize="20sp"
android:layout_alignTop="#+id/textView5"
android:layout_alignParentStart="true" />
<TextView
android:text="Tider:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView5"
android:layout_marginTop="14dp"
android:layout_below="#+id/description"
android:layout_alignParentStart="true" />
<TextView
android:text="Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_marginEnd="13dp"
android:layout_marginTop="10dp"
android:id="#+id/time"
android:textSize="25sp"
android:layout_marginLeft="0dp" />
</RelativeLayout>
</LinearLayout>
<View
android:id="#+id/dividerView"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="#+id/temp"
android:background="#color/colorPrimary" />
<ScrollView
android:id="#+id/eventScrollView"
android:layout_width="match_parent"
android:overScrollMode="never"
android:layout_below="#+id/dividerView"
android:padding="0dp"
android:scrollbars="none"
android:fadingEdge="none"
android:layout_height="fill_parent">
<RelativeLayout
android:id="#+id/eventRelativeLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="510dp">
</RelativeLayout>
</ScrollView>
Margin is set in the LayoutParams (e.g., RelativeLayout.LayoutParams in your case) as
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(left, top, right, bottom);
viewEvent.setLayoutParams(params);
Update
If you need to add the TextViews vertically then use LinearLayout as
<!-- inside scrollview -->
<LinearLayout
android:id="#+id/eventLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
And programmatically as
LinearLayout linearLayout = (LinearLayout) eventView.findViewById(R.id.eventLinearLayout);
for (int i = 0; i < partEvents.length; i++) {
TextView viewEvent = new TextView(getActivity());
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(left, top, right, bottom);
viewEvent.setLayoutParams(params);
// rest of your code
linearLayout.addView(viewEvent);
}
Using LinearLayout, would automatic handling your TextView expansion and shrinking.

Rating bar shows more stars when I rotate my application

I have this weird issue with my rating bar stars.
This is my app in vertical position
This is my app in horizontal position
As you can see the stars completely change
This is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/main"
tools:context="com.example.draganam.blankapp.Nivo1Activity">
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shrinkColumns="1,0" android:stretchColumns="0,1">
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="50dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/slika0"
android:src="#drawable/becutan1"
android:layout_column="0"
android:layout_marginRight="40px" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/slika1"
android:src="#drawable/blizoo1"
android:layout_column="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<RatingBar
android:id="#+id/rb0"
style="?android:attr/ratingBarStyleIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:isIndicator="true"
android:scaleX="0.7"
android:scaleY="0.7"/>
<RatingBar
android:id="#+id/rb1"
style="?android:attr/ratingBarStyleIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:isIndicator="true"
android:scaleX="0.7"
android:scaleY="0.7"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="50dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/slika2"
android:src="#drawable/brilijant1"
android:layout_column="0"
android:layout_marginRight="40px" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/slika3"
android:src="#drawable/vitaminka1"
android:layout_column="1" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<RatingBar
android:id="#+id/rb2"
style="?android:attr/ratingBarStyleIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:isIndicator="true"
android:scaleX="0.7"
android:scaleY="0.7"/>
<RatingBar
android:id="#+id/rb3"
style="?android:attr/ratingBarStyleIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="1.0"
android:isIndicator="true"
android:scaleX="0.7"
android:scaleY="0.7"/>
</TableRow>
</TableLayout>
</RelativeLayout>
This is my java code:
Context ctx2 = this;
String[][] arrayWithInformations = new String[5][];
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nivo1);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
DatabaseOperations databaseOperations = new DatabaseOperations(ctx2);
Cursor cursorLogo = databaseOperations.getInformationsForLogos(databaseOperations);
// looping through all rows and adding to list
Integer i = 0;
if (cursorLogo.moveToFirst()) {
do {
String[] helperArray = {cursorLogo.getString(0),cursorLogo.getString(1),cursorLogo.getString(2),cursorLogo.getString(3),
cursorLogo.getString(4),cursorLogo.getString(5)};
arrayWithInformations[i] = helperArray;
i++;
} while (cursorLogo.moveToNext());
}
int firstRating = Integer.parseInt(arrayWithInformations[0][4]);
int secondRating = Integer.parseInt(arrayWithInformations[1][4]);
int thirdRating = Integer.parseInt(arrayWithInformations[2][4]);
int fourthRating = Integer.parseInt(arrayWithInformations[3][4]);
RatingBar rb0 = (RatingBar) findViewById(R.id.rb0);
rb0.setRating(firstRating);
RatingBar rb1 = (RatingBar) findViewById(R.id.rb1);
rb1.setRating(secondRating);
RatingBar rb2 = (RatingBar) findViewById(R.id.rb2);
rb2.setRating(thirdRating);
RatingBar rb3 = (RatingBar) findViewById(R.id.rb3);
rb3.setRating(fourthRating);
I get the rating values from database file and everything works fine , the stars are ok but when I rotate the phone they are all wrong. I know that when u rotate your phone the current activity gets loaded again, but it's the same code and it loads wrong. Maybe it's multiplying the stars.. I may sound funny but I have no idea what is going wrong. Someone please give me a lead..
I found out the problem !
android:shrinkColumns="1,0" android:stretchColumns="0,1"
Setting this to the TableLayout caused this strange issue.
Thanks everyone for your interest in helping me ..

ImageView does not show up when added to a TableRow programmatically

Here are the relevant code bits:
<HorizontalScrollView
android:id="#+id/cards_scrollview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:fillViewport="false" >
<TableRow
android:id="#+id/cards_container"
android:layout_width="wrap_content"
android:layout_height="100dp" >
<ImageView
android:id="#+id/test_card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="#dimen/cards_distance"
android:adjustViewBounds="true"
android:src="#drawable/card_back" />
</TableRow>
</HorizontalScrollView>
and
private void addCard(Drawable d) {
TableRow container = (TableRow) findViewById(R.id.cards_container);
ImageView card = new ImageView(this);
card.setAdjustViewBounds(true);
card.setPadding(R.dimen.zero, R.dimen.zero, R.dimen.cards_distance, R.dimen.zero);
TableRow.LayoutParams params = new TableRow.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
card.setLayoutParams(params);
card.setImageDrawable(d);
card.setVisibility(View.VISIBLE);
container.addView(card);
}
I'm positively sure the Drawable I'm trying to add is not null, has the bounds properly set, the alpha set to 255, and fits properly. I've tested this by applying it to test_card instead of trying to add new ImageViews, which works perfectly.
Is there anything I'm missing here?
After an hour of tinkering with the code, it turns out setPadding() actually takes ints and not resource references as arguments, and that's what was messing it all up.
So basically all I needed to do was change:
card.setPadding(R.dimen.zero, R.dimen.zero, R.dimen.cards_distance, R.dimen.zero);
to
card.setPadding(0, 0, 5, 0);

Categories