我在textview中显示文本,看起来太长,无法放入一个屏幕.我需要让我的TextView可滚动.我怎样才能做到这一点?
这是代码:
final TextView tv = new TextView(this);
tv.setBackgroundResource(R.drawable.splash);
tv.setTypeface(face);
tv.setTextSize(18);
tv.setTextColor(R.color.BROWN);
tv.setGravity(Gravity.CENTER_VERTICAL| Gravity.CENTER_HORIZONTAL);
tv.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent e) {
Random r = new Random();
int i = r.nextInt(101);
if (e.getAction() == e.ACTION_DOWN) {
tv.setText(tips[i]);
tv.setBackgroundResource(R.drawable.inner);
}
return true;
}
});
setContentView(tv);
Run Code Online (Sandbox Code Playgroud) 我想通过一个小修改来创建一个默认的警报对话框.我在哪里可以找到默认AlertDialog的xml布局文件?
我想在AlertDialog中添加一个垂直滚动条,因为我的文字太长而无法在1个屏幕上显示:
我试过用:
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
Run Code Online (Sandbox Code Playgroud)
但滚动条甚至不显示?
这是我正在使用的xml布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:id="@+id/instructions_view" >
<TextView
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A LONG TEXT 1"/>
<TextView
android:id="@+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A LONG TEXT 2"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我用以下方法调用AlertsDialog:
public void onClick(View v) {
switch(v.getId()){
case R.id.Button_Instructions:
InstructionsDialog();
break;
case R.id.Button_Exit:
ExitDialog();
break;
}
}
public void InstructionsDialog(){
AlertDialog.Builder ad = new AlertDialog.Builder(this);
ad.setIcon(R.drawable.icon);
ad.setTitle("Instructions ...");
ad.setView(LayoutInflater.from(this).inflate(R.layout.instructions_dialog,null));
ad.setPositiveButton("OK",
new android.content.DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
// OK, go back to Main menu
} …Run Code Online (Sandbox Code Playgroud) 我试图DialogFragment弹出并显示可滚动TextView图例,但它只是切断了图例的其余部分。我无法滚动浏览它或任何东西。我尝试添加 aScrollView但它没有任何作用。这是我得到的屏幕:
这是我的 XML 布局文件:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:background="#fff">
<TextView
android:id="@+id/layer_legend_title_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="#fff"
android:textColor="#000" />
<ListView
android:id="@+id/layer_legend_symbols_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:background="#fff"
android:textColor="#000" />
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
我运行此命令将内容添加到TextView:
/**
* A dialog that shows the legend of a ArcGISDynamicMapServiceLayer.
*/
public class LegendDialogFragment extends DialogFragment implements View.OnClickListener {
public static final String TAG = LegendDialogFragment.class.getSimpleName();
private LinearLayout mLinearLayout;
private ArcGISDynamicMapServiceLayer …Run Code Online (Sandbox Code Playgroud) android arcgis android-layout android-scrollview android-dialogfragment