나는 채팅 메시지를 적절히 정렬해야하는 채팅 응용 프로그램을 만들고 있습니다. 사용자의 오른쪽과 다른 사용자를 왼쪽으로 정렬해야합니다. 메시지가 표시된 목록 뷰가 있습니다. 지금은 , 나는 데이터를 얻기 위해 번들 된 json을 사용하고있다. 내 코드는프로그래밍 방식으로 레이아웃에 중력을 설정하는 방법은 무엇입니까?
이것은 사용자가 입력 한 메시지에 문자열을 추가하기위한 것이다.
그 후final EditText et = (EditText)findViewById(R.id.EditText1);
final Button imb=(Button)findViewById(R.id.btn_send);
imb.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
String str = et.getText().toString()+":aeiou";
web.add(str);
scrollMyListViewToBottom();
et.setText(" ");
adapter.notifyDataSetChanged();
}
난 스트링을 분할하고, 첨부 된 문자열이있는 경우 메시지 user.ie에서, 다음 배치의 중력은 오른쪽으로 설정해야하는 array.If에 저장하고, 그렇지 않으면 왼쪽. 나는이 잘못 이것은 무엇
mychat=web.get(position);
if(mychat.contains(":"))
{
String[] splitted = mychat.split(":");
String chats;
if(splitted[1].equalsIgnoreCase("aeiou"))
{
chats=splitted[0];
Toast.makeText(context, "You entered...."+chats, Toast.LENGTH_SHORT).show();
LinearLayout my_layout = (LinearLayout) rowView.findViewById(R.id.main_layout);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.RIGHT;
my_layout.setLayoutParams(params);
//my_layout.setGravity(Gravity.RIGHT);
txtTitle.setText(chats);
}
}
else
{
txtTitle.setText(web.get(position));
}
txtTitle.setBackgroundResource(R.drawable.test);
내 어댑터 클래스에서이 코드를 사용? 도와주세요 ... 여기
내 XML<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#2a2a34"
android:padding="3dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/chat_icon_layout"
android:layout_width="match_parent"
android:layout_weight="4"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/img"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/white" />
<ImageView
android:id="@+id/img1"
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/abs__ab_bottom_solid_light_holo" />
</RelativeLayout>
<LinearLayout
android:id="@+id/chat_text_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp"
android:layout_weight="1" >
<TextView
android:id="@+id/txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Message"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
예 ... 다시 여기에 ... –
무엇 hmmmmmmmmmmmmmmmm –
내가 얼마나 바보 핑 소리를 들었는지 확인하십시오 :/나는 U가 지진으로 천국에 갔던 것처럼 생각합니다 :/:/ – Nevaeh