I'm trying to make a chat app, and having a trouble with setting gravity of custom view in the RecyclerView. I've been searching and trying a whole day, but i couldn't make, it always shows like this(ScreenShot).It should be located right of screen not left. But in Android Studio Preview, It shows correctly.Im attaching my source.. please tell me what's wrong..
In MainActivity.xml (RecyclerView)
...... <RelativeLayout android:background="#9cbad8" android:layout_weight="70" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:layout_alignParentRight="true" android:paddingBottom="5dp" android:listSelector="@drawable/bg_transparent" android:cacheColorHint="@android:color/transparent" android:paddingTop="50dp" android:id="@+id/list" android:layout_width="match_parent" android:layout_height="match_parent"/> </RelativeLayout> .......
2.In MessageItem.xml (I set graivity Right, and screenshot shows correctly)
<LinearLayout
android:id="@+id/my_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/my_normal_layout"
android:orientation="horizontal"
android:gravity="end"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/my_time"
android:textSize="10sp"
android:layout_marginRight="5dp"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="오후 15:15"/>
<TextView
android:textAlignment="center"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:maxWidth="200dp"
android:textSize="14sp"
android:lineSpacingMultiplier="1.2"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:paddingRight="15dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:background="@drawable/bubble_my"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:text="this is Test"
android:id="@+id/my_normal_text" />
</LinearLayout>
</LinearLayout>
Android Layout Preview shows well(ScreenShot)
My RecyclerViewHolder
public class ViewHolder extends RecyclerView.ViewHolder { LinearLayout myLayout; LinearLayout myNormarLayout; LinearLayout myMoreLayout; public ViewHolder(View v) { super(v); myLayout = (LinearLayout)v.findViewById(R.id.my_layout); myNormarLayout = (LinearLayout)v.findViewById(R.id.my_normal_layout); myMoreLayout = (LinearLayout)v.findViewById(R.id.my_more_layout); } }
Also in my RecyclerViewAdapter, I changed Gravity Again..
.... holder.myNormarLayout.setVisibility(View.VISIBLE); holder.myNormarLayout.setGravity(Gravity.Right); ....
I had tried almost of things from searching, but they didn't work for this.. please... help me