是否有可能(或许用linkify),直接链接到一个文本链接一个段落?
例如,我有一个目录与以下内容:
定义标志及放大器;症状治疗等等在相同的布局我有文字或对应于这些条目的标题。我想在目录中的文本点击跳转到我的内容具体标题:如我点击标志和放大器;症状,这将直接跳转到标记部分的内容的症状和体征
感谢。
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android 的xmlns:工具=http://schemas.android.com/tools 机器人:layout_width =match_parent 机器人:layout_height =match_parent 机器人:背景=#FFFFFF 机器人:paddingBottom会=@扪/ activity_vertical_margin 机器人:paddingLeft =@扪/ activity_horizontal_margin 机器人:paddingRight =@扪/ activity_horizontal_margin 机器人:paddingTop =@扪/ activity_vertical_margin 工具:上下文=动脉粥样硬化 工具:忽略=UselessParent,ScrollViewCount><滚动型 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT> < RelativeLayout的 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT><的LinearLayout 机器人:ID =@ + ID / tablecontentlayout 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:方向=垂直 机器人:背景=#FAFAD2> <的TextView 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:TEXTSIZE =16SP 机器人:文字样式=大胆 机器人:文字颜色=#000000 机器人:文字=@字符串/表/> <的TextView 机器人:ID =@ + ID / definitionid 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆 机器人:文字颜色=#4682B4 机器人:文字=@字符串/定义/> <的TextView 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆 机器人:文字颜色=#4682B4 机器人:文字=@字符串/ RiskFactors/> <的TextView 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆 机器人:文字颜色=#4682B4 机器人:文字=@字符串/病理生理学/> <的TextView 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆 机器人:文字颜色=#4682B4 机器人:文字=@字符串/ SignsandSymptoms/> <的TextView 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆 机器人:文字颜色=#4682B4 机器人:文字=@字符串/诊断/> <的TextView 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆 机器人:文字颜色=#4682B4 机器人:文字=@字符串/治疗/> <的TextView 机器人:layout_width =WRAP_CONTENT 机器人:layout_height =WRAP_CONTENT 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆 机器人:文字颜色=#4682B4 机器人:文字=@字符串/ prevention/> < / LinearLayout中> <的LinearLayout 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:layout_below =@ + ID / tablecontentlayout 机器人:layout_marginTop =15dp 机器人:方向=垂直> <的TextView 机器人:ID =@ + ID / atherodefinition 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/定义 机器人:背景=#F5F5F5 机器人:文字颜色=#483D8B 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/ atherosclerosisdefinition 机器人:TEXTSIZE =15sp/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/ RiskFactors 机器人:背景=#F5F5F5 机器人:文字颜色=#483D8B 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/修改的 机器人:文字样式=大胆 机器人:TEXTSIZE =15sp/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/ modifiableatherosclerosis 机器人:TEXTSIZE =15sp/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/不可改变 机器人:文字样式=大胆 机器人:TEXTSIZE =15sp/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/ nonmodifiableatherosclerosis 机器人:TEXTSIZE =15sp/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/病理生理学 机器人:背景=#F5F5F5 机器人:文字颜色=#483D8B 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/ pathophysiologyatherosclerosis 机器人:TEXTSIZE =15sp/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/ SignsandSymptoms 机器人:背景=#F5F5F5 机器人:文字颜色=#483D8B 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/ atherosclerosissignsandsymptoms 机器人:TEXTSIZE =15sp/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/诊断 机器人:背景=#F5F5F5 机器人:文字颜色=#483D8B 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/ Diagnosisatherosclerosis 机器人:TEXTSIZE =15sp/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/治疗 机器人:背景=#F5F5F5 机器人:文字颜色=#483D8B 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/ treatmentatherosclerosis 机器人:TEXTSIZE =15sp/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/ prevention 机器人:背景=#F5F5F5 机器人:文字颜色=#483D8B 机器人:TEXTSIZE =15sp 机器人:文字样式=大胆/> <的TextView 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:文字=@字符串/ preventionatherosclerosis 机器人:TEXTSIZE =15sp/> < / LinearLayout中> < / RelativeLayout的> < /滚动型>< / RelativeLayout的>
公共类动脉粥样硬化延伸活动{
@覆盖 保护无效的onCreate(捆绑savedInstanceState){ super.onCreate(savedInstanceState); 的setContentView(R.layout.atherosclerosis); TextView的电视=(的TextView)findViewById(R.id.definitionid); tv.setOnClickListener(新View.OnClickListener(){ @覆盖 公共无效的onClick(视图v){ } }); } @覆盖 公共布尔onCreateOptionsMenu(菜单菜单){ //充气菜单;如果是present这增加了项目操作栏。 。getMenuInflater()膨胀(R.menu.atherosclerosis,菜单); 返回true; } }
解决方案
我会使用 scrollTo 滚动型的方法。
这是标题设置的OnClickListener,并在onClick的方法,获得通过的共达从视图方法和向下滚动到该位置。
例如:
的TextView signsAndSymptomsHeader;滚动型滚动视图;//做视图,设置等必要的初始化...//然后在onCreate方法如下signsAndSymptomsHeader.setOnClickListener(新View.OnClickListener(){ @覆盖 的onClick(视图v){ 开关(v.getId()){ 案例R.id.id_of_signs_symptoms_content: scrollView.scrollTo(0,v.getTop()); 打破; //重复所有的标题。 } }});
Is it possible to link directly to a paragraph from a text link (perhaps using "linkify")?
For example, I have a table of contents with the following:
Definition signs & symptoms treatment etc. In the same layout I have the text or headings that which correspond to these entries. I want a click on the text in the table of contents to jump to that specific heading in my content: e.g. I click on "signs & symptoms" and this jumps directly to the section marked "signs and symptoms" in the content.
Thanks.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Atherosclerosis"
tools:ignore="UselessParent,ScrollViewCount" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/tablecontentlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#FAFAD2" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#000000"
android:text="@string/table" />
<TextView
android:id="@+id/definitionid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="@string/Definition" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="@string/RiskFactors" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="@string/Pathophysiology" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="@string/SignsandSymptoms" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="@string/Diagnosis" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="@string/Treatment" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"
android:textStyle="bold"
android:textColor="#4682B4"
android:text="@string/Prevention" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tablecontentlayout"
android:layout_marginTop="15dp"
android:orientation="vertical" >
<TextView
android:id="@+id/atherodefinition"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Definition"
android:background="#F5F5F5"
android:textColor="#483D8B"
android:textSize="15sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/atherosclerosisdefinition"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/RiskFactors"
android:background="#F5F5F5"
android:textColor="#483D8B"
android:textSize="15sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Modifiable"
android:textStyle="bold"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/modifiableatherosclerosis"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Nonmodifiable"
android:textStyle="bold"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/nonmodifiableatherosclerosis"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Pathophysiology"
android:background="#F5F5F5"
android:textColor="#483D8B"
android:textSize="15sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pathophysiologyatherosclerosis"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/SignsandSymptoms"
android:background="#F5F5F5"
android:textColor="#483D8B"
android:textSize="15sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/atherosclerosissignsandsymptoms"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Diagnosis"
android:background="#F5F5F5"
android:textColor="#483D8B"
android:textSize="15sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Diagnosisatherosclerosis"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Treatment"
android:background="#F5F5F5"
android:textColor="#483D8B"
android:textSize="15sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/treatmentatherosclerosis"
android:textSize="15sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Prevention"
android:background="#F5F5F5"
android:textColor="#483D8B"
android:textSize="15sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Preventionatherosclerosis"
android:textSize="15sp"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
public class Atherosclerosis extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.atherosclerosis);
TextView tv = (TextView)findViewById(R.id.definitionid);
tv.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.atherosclerosis, menu);
return true;
}
}
解决方案
I would use the scrollTo method of ScrollView.
Set an OnClickListener on the headings, and in the onClick method, get the X coordinate of the top of the paragraph using the getTop method from View and scroll down to that position.
For example :
TextView signsAndSymptomsHeader;
ScrollView scrollView;
// do necessary initializations of Views, setup etc ...
// then the following in your onCreate method
signsAndSymptomsHeader.setOnClickListener(new View.OnClickListener(){
@Override
onClick(View v){
switch (v.getId()){
case R.id.id_of_signs_symptoms_content :
scrollView.scrollTo(0,v.getTop());
break;
// repeat for all headers.
}
}
});