Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <com.atvtremote.NotFocusableScrollView
- android:id="@+id/messages_scroll"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:nestedScrollingEnabled="true"
- android:layout_above="@+id/send_panel"
- android:background="@android:color/transparent"
- android:padding="5dp">
- <LinearLayout
- android:id="@+id/messages"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="bottom"
- android:animateLayoutChanges="true"
- android:orientation="vertical"/>
- </com.atvtremote.NotFocusableScrollView>
- private void addMessage(String message, String userName, int step) {
- View v = activity.getLayoutInflater().inflate(R.layout.chat_msg_item, null);
- TextView name = (TextView) v.findViewById(R.id.user_name);
- TextView msg = (TextView) v.findViewById(R.id.msg_body);
- LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams
- .WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- params.setMargins(0, 5, 0, 5);
- if (messageIds.contains(messageId)) {
- params.gravity = Gravity.LEFT;
- v.setBackground(context.getResources().getDrawable(R.drawable.chat_msg_me));
- messageIds.remove(messageId);
- } else {
- params.gravity = Gravity.RIGHT;
- }
- if (messageIds.size() == 0) {
- infoSending.setVisibility(View.GONE);
- }
- name.setText("@" + userName);
- msg.setText(message);
- switch (step) {
- case 0:
- msg.setTextColor(context.getResources()
- .getColor(android.R.color.holo_green_dark));
- break;
- case 1:
- msg.setTextColor(context.getResources()
- .getColor(android.R.color.holo_red_dark));
- break;
- case 2:
- msg.setTextColor(Color.BLACK);
- break;
- }
- v.setLayoutParams(params);
- v.requestLayout();
- messages.addView(v);
- // if (messages.getHeight() > (messagesScroll.getHeight()/2)) {
- // messages.removeViewAt(0);
- // }
- if ((messages.getHeight()+100) > messagesScroll.getHeight()) {
- messages.removeViewAt(0);
- }
- }
- public class NotFocusableScrollView extends ScrollView {
- public NotFocusableScrollView(Context context) {
- super(context);
- }
- public NotFocusableScrollView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
- public NotFocusableScrollView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
- @Override
- protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement