[英]TextView out of the Screen
I'm building a chat Application, So I'm displaying bubbles as background of the textView and also an imageView. 我正在构建一个聊天应用程序,因此我将气泡显示为textView和imageView的背景。
To be able to differ messages from users, I hide a imageView (using visibilty.Gone) and change the layout_gravity to right ou left to correctly display the message. 为了能够区别来自用户的消息,我隐藏了一个imageView(使用visibilty.Gone),并将layout_gravity更改为从右到左以正确显示消息。
Everything is working great, except when the message from the "Mark Zuckerberg" (and only when it's from him) is too longo, the textview goes out of the screen. 一切工作都很好,除非来自“马克·扎克伯格”的消息(并且仅当来自他的消息)太长时,textview不在屏幕上。
Here is my layout: 这是我的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<br.com.guitcastro.meetapp.views.CircularImageView
android:id="@+id/leftImageView"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_vertical"
android:padding="10dp"
android:paddingLeft="10dp"
android:visibility="visible" />
<TextView
android:id="@+id/comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="@drawable/bubble_purple"
android:gravity="center_vertical|center_horizontal"
android:text="Hello bubbles! This is a very ver"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/primary_text_light" />
<br.com.guitcastro.meetapp.views.CircularImageView
android:id="@+id/rightImageView"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_vertical"
android:padding="10dp"
android:paddingLeft="10dp"
android:visibility="visible" />
</LinearLayout>
The code to display the "right" layout: 显示“正确”布局的代码:
if (left) {
rightImageView.setVisibility(View.GONE);
leftImageView.setVisibility(View.VISIBLE);
messageText.setTextColor(Color.WHITE);
this.setImageDrawable(leftImageView, me);
messageText.setBackgroundResource(R.drawable.bubble_green);
wrapper.setGravity(Gravity.LEFT);
} else {
leftImageView.setVisibility(View.GONE);
rightImageView.setVisibility(View.VISIBLE);
this.setImageDrawable(rightImageView, StringUtils.parseName(message.getFrom()));
messageText.setBackgroundResource(R.drawable.bubble_yellow);
wrapper.setGravity(Gravity.RIGHT);
}
Here is a screenShot, what I have for now (I know the bubbles are wrong, please ignore, this isn't important right now). 这是我现在拥有的一个screenShot(我知道气泡是错误的,请忽略,这现在不重要)。
maybe this can help you
// get dimensions
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth(); // largura
// get dimensions in percent
double percentWidth = width/100;
int percentToSetHeight = percentHeight*80;
if (left) {
rightImageView.setVisibility(View.GONE);
leftImageView.setVisibility(View.VISIBLE);
messageText.setTextColor(Color.WHITE);
messageText.setMaxWidth(percentToSetHeight);
this.setImageDrawable(leftImageView, me);
messageText.setBackgroundResource(R.drawable.bubble_green);
wrapper.setGravity(Gravity.LEFT);
} else {
leftImageView.setVisibility(View.GONE);
rightImageView.setVisibility(View.VISIBLE);
this.setImageDrawable(rightImageView, StringUtils.parseName(message.getFrom()));
messageText.setMaxWidth(percentToSetHeight);
messageText.setBackgroundResource(R.drawable.bubble_yellow);
wrapper.setGravity(Gravity.RIGHT);
}
// try this way,hope this will help you...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/wrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<br.com.guitcastro.meetapp.views.CircularImageView
android:id="@+id/leftImageView"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_vertical"
android:padding="10dp"
android:paddingLeft="10dp"
android:visibility="visible" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:id="@+id/comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:background="@drawable/bubble_purple"
android:gravity="center"
android:text="Hello bubbles! This is a very ver"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/primary_text_light" />
</LinearLayout>
<br.com.guitcastro.meetapp.views.CircularImageView
android:id="@+id/rightImageView"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center_vertical"
android:padding="10dp"
android:paddingLeft="10dp"
android:visibility="visible" />
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.